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:
Simon Vrouwe
2021-12-06 16:28:55 +02:00
committed by Rusty Russell
parent be196b4219
commit f936fa926f
6 changed files with 9 additions and 30 deletions

View File

@@ -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)) {