From 456078150a204a3217aa5466007bc19595add19b Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sat, 4 Feb 2023 15:46:24 +1030 Subject: [PATCH] lightningd: tell connectd we're shutting down. Signed-off-by: Rusty Russell --- lightningd/connect_control.c | 26 ++++++++++++++++++++++++++ lightningd/connect_control.h | 1 + lightningd/lightningd.c | 3 +++ lightningd/test/run-find_my_abspath.c | 3 +++ 4 files changed, 33 insertions(+) diff --git a/lightningd/connect_control.c b/lightningd/connect_control.c index 553061c07..ca50c7c42 100644 --- a/lightningd/connect_control.c +++ b/lightningd/connect_control.c @@ -522,6 +522,32 @@ static void handle_custommsg_in(struct lightningd *ld, const u8 *msg) plugin_hook_call_custommsg(ld, NULL, p); } +static void connectd_start_shutdown_reply(struct subd *connectd, + const u8 *reply, + const int *fds UNUSED, + void *unused UNUSED) +{ + if (!fromwire_connectd_start_shutdown_reply(reply)) + fatal("Bad connectd_start_shutdown_reply: %s", + tal_hex(reply, reply)); + + /* Break out of loop now, so we can continue shutdown. */ + log_debug(connectd->ld->log, "io_break: %s", __func__); + io_break(connectd); +} + +void connectd_start_shutdown(struct subd *connectd) +{ + const u8 *msg = towire_connectd_start_shutdown(NULL); + + subd_req(connectd, connectd, take(msg), -1, 0, + connectd_start_shutdown_reply, NULL); + + /* Wait for shutdown_reply. Note that since we're shutting down, + * start_json_stream can io_break too! */ + while (io_loop(NULL, NULL) != connectd); +} + static unsigned connectd_msg(struct subd *connectd, const u8 *msg, const int *fds) { enum connectd_wire t = fromwire_peektype(msg); diff --git a/lightningd/connect_control.h b/lightningd/connect_control.h index bea039a68..3d9299db1 100644 --- a/lightningd/connect_control.h +++ b/lightningd/connect_control.h @@ -17,6 +17,7 @@ struct wireaddr_internal; /* Returns fd for gossipd to talk to connectd */ int connectd_init(struct lightningd *ld); void connectd_activate(struct lightningd *ld); +void connectd_start_shutdown(struct subd *connectd); void try_reconnect(const tal_t *ctx, struct peer *peer, diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index 361b245a4..b4771d98c 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -1235,6 +1235,9 @@ stop: /* Stop *new* JSON RPC requests. */ jsonrpc_stop_listening(ld->jsonrpc); + /* Stop new connectd requests */ + connectd_start_shutdown(ld->connectd); + /* Give permission for things to get destroyed without getting upset. */ ld->state = LD_STATE_SHUTDOWN; diff --git a/lightningd/test/run-find_my_abspath.c b/lightningd/test/run-find_my_abspath.c index 0471f97b2..ad9c21095 100644 --- a/lightningd/test/run-find_my_abspath.c +++ b/lightningd/test/run-find_my_abspath.c @@ -20,6 +20,9 @@ void connectd_activate(struct lightningd *ld UNNEEDED) /* Generated stub for connectd_init */ int connectd_init(struct lightningd *ld UNNEEDED) { fprintf(stderr, "connectd_init called!\n"); abort(); } +/* Generated stub for connectd_start_shutdown */ +void connectd_start_shutdown(struct subd *connectd UNNEEDED) +{ fprintf(stderr, "connectd_start_shutdown called!\n"); abort(); } /* Generated stub for daemon_poll */ int daemon_poll(struct pollfd *fds UNNEEDED, nfds_t nfds UNNEEDED, int timeout UNNEEDED) { fprintf(stderr, "daemon_poll called!\n"); abort(); }