diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index cfb0398ef..54b47317d 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -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 */ diff --git a/lightningd/plugin.c b/lightningd/plugin.c index 142f20ed1..d1e785468 100644 --- a/lightningd/plugin.c +++ b/lightningd/plugin.c @@ -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)) { diff --git a/lightningd/plugin_hook.c b/lightningd/plugin_hook.c index a1aa68cca..29a5de2aa 100644 --- a/lightningd/plugin_hook.c +++ b/lightningd/plugin_hook.c @@ -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) diff --git a/wallet/db.c b/wallet/db.c index f0117c063..bfbd9a729 100644 --- a/wallet/db.c +++ b/wallet/db.c @@ -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; diff --git a/wallet/db.h b/wallet/db.h index 9907fdcbd..e51e75fd6 100644 --- a/wallet/db.h +++ b/wallet/db.h @@ -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. */ diff --git a/wallet/db_common.h b/wallet/db_common.h index ea635f7eb..0ab196c29 100644 --- a/wallet/db_common.h +++ b/wallet/db_common.h @@ -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;