From 0841e4190b831c7f345ee53ae5b726978d01fb8e Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 11 Jan 2022 11:46:55 +1030 Subject: [PATCH] connectd: also do the shutdown()-close for final_msg sends. Signed-off-by: Rusty Russell --- connectd/multiplex.c | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/connectd/multiplex.c b/connectd/multiplex.c index 55f23f64e..a5cebf4ab 100644 --- a/connectd/multiplex.c +++ b/connectd/multiplex.c @@ -142,20 +142,6 @@ void setup_peer_gossip_store(struct peer *peer, } } -/* These four function handle subd->peer */ -static struct io_plan *after_final_msg(struct io_conn *peer_conn, - struct peer *peer) -{ - /* io_close will want to free this itself! */ - assert(peer->to_peer == peer_conn); - - /* Invert ownership, so io_close frees peer for us */ - tal_steal(NULL, peer_conn); - tal_steal(peer_conn, peer); - - return io_close(peer_conn); -} - /* We're happy for the kernel to batch update and gossip messages, but a * commitment message, for example, should be instantly sent. There's no * great way of doing this, unfortunately. @@ -415,15 +401,15 @@ static struct io_plan *write_to_peer(struct io_conn *peer_conn, /* Pop tail of send queue */ msg = msg_dequeue(peer->peer_outq); - /* Nothing to send? */ - if (!msg) { - /* Send final once subd is not longer connected */ - if (peer->final_msg && !peer->to_subd) { - return encrypt_and_send(peer, - peer->final_msg, - after_final_msg); - } + /* Is it time to send final? */ + if (!msg && peer->final_msg && !peer->to_subd) { + /* OK, send this then close. */ + msg = peer->final_msg; + peer->final_msg = NULL; + } + /* Still nothing to send? */ + if (!msg) { /* We close once subds are all closed. */ if (!peer->to_subd) { set_closing_timer(peer, peer_conn); @@ -641,6 +627,7 @@ struct io_plan *multiplex_peer_setup(struct io_conn *peer_conn, void multiplex_final_msg(struct peer *peer, const u8 *final_msg TAKES) { + peer->told_to_close = true; peer->final_msg = tal_dup_talarr(peer, u8, final_msg); if (!peer->to_subd) io_wake(peer->peer_outq);