Skip to content

Commit 19300de

Browse files
rustyrussellcdecker
authored andcommitted
lightningd: correctly exit when an important-plugin fails to start.
This was found by tests/test_plugin.py::test_important_plugin and was NOT a flake! Signed-off-by: Rusty Russell <[email protected]> Changelog-None: only just committed
1 parent 110ed3b commit 19300de

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed

lightningd/chaintopology.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,7 @@ struct chain_topology *new_topology(struct lightningd *ld, struct log *log)
968968
topo->feerate_uninitialized = true;
969969
topo->root = NULL;
970970
topo->sync_waiters = tal(topo, struct list_head);
971+
topo->extend_timer = NULL;
971972
topo->stopping = false;
972973
list_head_init(topo->sync_waiters);
973974

lightningd/lightningd.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ int main(int argc, char *argv[])
876876
struct htlc_in_map *unconnected_htlcs_in;
877877
struct ext_key *bip32_base;
878878
int sigchld_rfd;
879-
struct io_conn *sigchld_conn;
879+
struct io_conn *sigchld_conn = NULL;
880880
int exit_code = 0;
881881
char **orig_argv;
882882
bool try_reexec;
@@ -1104,7 +1104,8 @@ int main(int argc, char *argv[])
11041104

11051105
/*~ Now that the rpc path exists, we can start the plugins and they
11061106
* can start talking to us. */
1107-
plugins_config(ld->plugins);
1107+
if (!plugins_config(ld->plugins))
1108+
goto stop;
11081109

11091110
/*~ Process any HTLCs we were in the middle of when we exited, now
11101111
* that plugins (who might want to know via htlc_accepted hook) are
@@ -1201,6 +1202,7 @@ int main(int argc, char *argv[])
12011202
assert(io_loop_ret == ld);
12021203
log_debug(ld->log, "io_loop_with_timers: %s", __func__);
12031204

1205+
stop:
12041206
/* Stop *new* JSON RPC requests. */
12051207
jsonrpc_stop_listening(ld->jsonrpc);
12061208

lightningd/plugin.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,7 +1938,7 @@ plugin_config(struct plugin *plugin)
19381938
plugin->plugin_state = AWAITING_INIT_RESPONSE;
19391939
}
19401940

1941-
void plugins_config(struct plugins *plugins)
1941+
bool plugins_config(struct plugins *plugins)
19421942
{
19431943
struct plugin *p;
19441944
list_for_each(&plugins->plugins, p, list) {
@@ -1948,10 +1948,15 @@ void plugins_config(struct plugins *plugins)
19481948

19491949
/* Wait for them to configure, before continuing: large
19501950
* nodes can take a while to startup! */
1951-
if (plugins->startup)
1952-
io_loop_with_timers(plugins->ld);
1951+
if (plugins->startup) {
1952+
/* This happens if an important plugin fails init,
1953+
* or if they call shutdown now. */
1954+
if (io_loop_with_timers(plugins->ld) == plugins->ld)
1955+
return false;
1956+
}
19531957

19541958
plugins->startup = false;
1959+
return true;
19551960
}
19561961

19571962
/** json_add_opt_plugins_array

lightningd/plugin.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,11 @@ struct command_result *plugin_register_all_complete(struct lightningd *ld,
265265
* and send them over to the plugin. This finalizes the initialization
266266
* of the plugins and signals that lightningd is now ready to process
267267
* incoming JSON-RPC calls and messages.
268+
*
269+
* It waits for plugins to be initialized, but returns false if we
270+
* should exit (an important plugin failed, or we got a shutdown command).
268271
*/
269-
void plugins_config(struct plugins *plugins);
272+
bool plugins_config(struct plugins *plugins);
270273

271274
/**
272275
* This populates the jsonrpc request with the plugin/lightningd specifications

lightningd/test/run-find_my_abspath.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ struct chain_topology *new_topology(struct lightningd *ld UNNEEDED, struct log *
168168
void onchaind_replay_channels(struct lightningd *ld UNNEEDED)
169169
{ fprintf(stderr, "onchaind_replay_channels called!\n"); abort(); }
170170
/* Generated stub for plugins_config */
171-
void plugins_config(struct plugins *plugins UNNEEDED)
171+
bool plugins_config(struct plugins *plugins UNNEEDED)
172172
{ fprintf(stderr, "plugins_config called!\n"); abort(); }
173173
/* Generated stub for plugins_init */
174174
void plugins_init(struct plugins *plugins UNNEEDED)

0 commit comments

Comments
 (0)