Skip to content

Commit

Permalink
plugin: Do not forward plugin hook calls during shutdown
Browse files Browse the repository at this point in the history
We make the current state of `lightningd` explicit so we don't have to
identify a shutdown by its side-effects. We then use this in order to prevent
the killing and freeing of plugins to continue down the chain of registered
plugins.
  • Loading branch information
cdecker committed Feb 19, 2020
1 parent 508f98c commit f063328
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lightningd/lightningd.c
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,7 @@ int main(int argc, char *argv[])
* valgrind will warn us if we make decisions based on uninitialized
* variables. */
ld = new_lightningd(NULL);
ld->state = LD_STATE_RUNNING;

/* Figure out where our daemons are first. */
ld->daemon_dir = find_daemon_dir(ld, argv[0]);
Expand Down Expand Up @@ -931,6 +932,7 @@ int main(int argc, char *argv[])
* shut down.
*/
assert(io_loop_ret == ld);
ld->state = LD_STATE_SHUTDOWN;

/* Keep this fd around, to write final response at the end. */
stop_fd = io_conn_fd(ld->stop_conn);
Expand Down
7 changes: 7 additions & 0 deletions lightningd/lightningd.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ struct config {

typedef STRMAP(const char *) alt_subdaemon_map;

enum lightningd_state {
LD_STATE_RUNNING,
LD_STATE_SHUTDOWN,
};

struct lightningd {
/* The directory to find all the subdaemons. */
const char *daemon_dir;
Expand Down Expand Up @@ -262,6 +267,8 @@ struct lightningd {
struct list_head waitblockheight_commands;

alt_subdaemon_map alt_subdaemons;

enum lightningd_state state;
};

/* Turning this on allows a tal allocation to return NULL, rather than aborting.
Expand Down
7 changes: 7 additions & 0 deletions lightningd/plugin_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct plugin_hook_request {
void *cb_arg;
void *payload;
struct db *db;
struct lightningd *ld;
};

/* A link in the plugin_hook call chain (there's a joke in there about
Expand Down Expand Up @@ -156,6 +157,11 @@ static void plugin_hook_callback(const char *buffer, const jsmntok_t *toks,
bool more_plugins, cont;
struct plugin_hook_call_link *last;

if (r->ld->state == LD_STATE_SHUTDOWN) {
log_debug(r->ld->log,
"Abandoning plugin hook call due to shutdown");
return;
}
/* Pop the head off the call chain and continue with the next */
last = list_pop(&r->call_chain, struct plugin_hook_call_link, list);
assert(last != NULL);
Expand Down Expand Up @@ -228,6 +234,7 @@ void plugin_hook_call_(struct lightningd *ld, const struct plugin_hook *hook,
ph_req->db = ld->wallet->db;
ph_req->payload = tal_steal(ph_req, payload);
ph_req->current_plugin = -1;
ph_req->ld = ld;

list_head_init(&ph_req->call_chain);
for (size_t i=0; i<tal_count(hook->plugins); i++) {
Expand Down

0 comments on commit f063328

Please sign in to comment.