mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-19 05:44:12 +01:00
plugins: simplify shutdown loop, simply close the db
The only thing that needs ld->wallet after this is destroy_invoices_waiter (off jsonrpc) Could not find any other destructors (destroy_*) that need wallet or db access after this. Any db access would now segfault.
This commit is contained in:
parent
be196b4219
commit
f936fa926f
@ -1197,7 +1197,7 @@ int main(int argc, char *argv[])
|
||||
remove_sigchild_handler(sigchld_conn);
|
||||
shutdown_subdaemons(ld);
|
||||
|
||||
/* Tell plugins we're shutting down, closes the db for write access. */
|
||||
/* Tell plugins we're shutting down, closes the db. */
|
||||
shutdown_plugins(ld);
|
||||
|
||||
/* Cleanup JSON RPC separately: destructors assume some list_head * in ld */
|
||||
|
@ -2088,18 +2088,13 @@ void plugins_set_builtin_plugins_dir(struct plugins *plugins,
|
||||
NULL, NULL);
|
||||
}
|
||||
|
||||
static void plugin_shutdown_timeout(struct lightningd *ld)
|
||||
{
|
||||
io_break(plugin_shutdown_timeout);
|
||||
}
|
||||
|
||||
void shutdown_plugins(struct lightningd *ld)
|
||||
{
|
||||
struct plugin *p, *next;
|
||||
|
||||
/* Don't complain about important plugins vanishing and
|
||||
* crash any attempt to write to db. */
|
||||
/* Don't complain about important plugins vanishing; close the db. */
|
||||
ld->plugins->shutdown = true;
|
||||
ld->wallet->db = tal_free(ld->wallet->db);
|
||||
|
||||
/* Tell them all to shutdown; if they care. */
|
||||
list_for_each_safe(&ld->plugins->plugins, p, next, list) {
|
||||
@ -2110,20 +2105,17 @@ void shutdown_plugins(struct lightningd *ld)
|
||||
|
||||
/* If anyone was interested in shutdown, give them time. */
|
||||
if (!list_empty(&ld->plugins->plugins)) {
|
||||
struct timers *orig_timers, *timer;
|
||||
struct timers *timer;
|
||||
struct timer *expired;
|
||||
|
||||
/* 30 seconds should do it, use a clean timers struct */
|
||||
orig_timers = ld->timers;
|
||||
timer = tal(NULL, struct timers);
|
||||
timers_init(timer, time_mono());
|
||||
new_reltimer(timer, timer, time_from_sec(30),
|
||||
plugin_shutdown_timeout, ld);
|
||||
new_reltimer(timer, timer, time_from_sec(30), NULL, NULL);
|
||||
|
||||
void *ret = io_loop(timer, &expired);
|
||||
assert(ret == NULL || ret == destroy_plugin);
|
||||
|
||||
ld->timers = timer;
|
||||
void *ret = io_loop_with_timers(ld);
|
||||
assert(ret == plugin_shutdown_timeout || ret == destroy_plugin);
|
||||
ld->timers = orig_timers;
|
||||
tal_free(timer);
|
||||
|
||||
/* Report and free remaining plugins. */
|
||||
while (!list_empty(&ld->plugins->plugins)) {
|
||||
|
@ -338,7 +338,6 @@ void plugin_hook_db_sync(struct db *db)
|
||||
size_t i;
|
||||
size_t num_hooks;
|
||||
|
||||
db_check_plugins_not_shutdown(db);
|
||||
const char **changes = db_changes(db);
|
||||
num_hooks = tal_count(hook->hooks);
|
||||
if (num_hooks == 0)
|
||||
|
@ -1276,7 +1276,6 @@ struct db *db_setup(const tal_t *ctx, struct lightningd *ld,
|
||||
struct db *db = db_open(ctx, ld->wallet_dsn);
|
||||
bool migrated;
|
||||
db->log = new_log(db, ld->log_book, NULL, "database");
|
||||
db->plugins_shutdown = &ld->plugins->shutdown;
|
||||
|
||||
db_begin_transaction(db);
|
||||
|
||||
@ -2351,11 +2350,6 @@ void db_changes_add(struct db_stmt *stmt, const char * expanded)
|
||||
tal_arr_expand(&db->changes, tal_strdup(db->changes, expanded));
|
||||
}
|
||||
|
||||
void db_check_plugins_not_shutdown(struct db *db)
|
||||
{
|
||||
assert(!*db->plugins_shutdown);
|
||||
}
|
||||
|
||||
const char **db_changes(struct db *db)
|
||||
{
|
||||
return db->changes;
|
||||
|
@ -249,9 +249,6 @@ struct db_stmt *db_prepare_v2_(const char *location, struct db *db,
|
||||
#define db_prepare_v2(db,query) \
|
||||
db_prepare_v2_(__FILE__ ":" stringify(__LINE__), db, query)
|
||||
|
||||
/* Check that plugins are not shutting down when calling db_write hook */
|
||||
void db_check_plugins_not_shutdown(struct db *db);
|
||||
|
||||
/**
|
||||
* Access pending changes that have been added to the current transaction.
|
||||
*/
|
||||
|
@ -34,9 +34,6 @@ struct db {
|
||||
* Used to bump the data_version in the DB.*/
|
||||
bool dirty;
|
||||
|
||||
/* Only needed to check shutdown state of plugins */
|
||||
const bool *plugins_shutdown;
|
||||
|
||||
/* The current DB version we expect to update if changes are
|
||||
* committed. */
|
||||
u32 data_version;
|
||||
|
Loading…
Reference in New Issue
Block a user