diff --git a/connectd/connectd.c b/connectd/connectd.c index 587faf87c3..54442361a1 100644 --- a/connectd/connectd.c +++ b/connectd/connectd.c @@ -1812,8 +1812,10 @@ static void peer_discard(struct daemon *daemon, const u8 *msg) /* If it's reconnected already, it will learn soon. */ if (peer->counter != counter) return; + + /* We make sure any final messages from the subds are sent! */ status_peer_debug(&id, "discard_peer"); - tal_free(peer); + drain_peer(peer); } static void start_shutdown(struct daemon *daemon, const u8 *msg) diff --git a/connectd/multiplex.c b/connectd/multiplex.c index 2a7a295296..d24a23f5fb 100644 --- a/connectd/multiplex.c +++ b/connectd/multiplex.c @@ -108,7 +108,7 @@ static void close_subd_timeout(struct subd *subd) io_close(subd->conn); } -static void drain_peer(struct peer *peer) +void drain_peer(struct peer *peer) { status_debug("drain_peer"); assert(!peer->draining); diff --git a/connectd/multiplex.h b/connectd/multiplex.h index 77a41fa2aa..cc4beebadb 100644 --- a/connectd/multiplex.h +++ b/connectd/multiplex.h @@ -34,4 +34,8 @@ void send_custommsg(struct daemon *daemon, const u8 *msg); /* Lightningd wants to talk to you. */ void peer_connect_subd(struct daemon *daemon, const u8 *msg, int fd); + +/* Start shutting down peer. */ +void drain_peer(struct peer *peer); + #endif /* LIGHTNING_CONNECTD_MULTIPLEX_H */