From c1d3da889cf5eb307f9c5396963943dcef84af22 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 19 Jun 2023 14:07:54 +0930 Subject: [PATCH] tools/gossipwith: shutdown, don't close, TCP socket. This isn't the cause of the test_gossip_ratelimit flake I saw (since the final gossip msg clearly was received), but it's still good to fix since it means we might not send the final messages. Signed-off-by: Rusty Russell --- devtools/gossipwith.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/devtools/gossipwith.c b/devtools/gossipwith.c index 21dec7c23..8785ed915 100644 --- a/devtools/gossipwith.c +++ b/devtools/gossipwith.c @@ -246,6 +246,15 @@ static struct io_plan *handshake_success(struct io_conn *conn, --max_messages; } } + + /* Simply closing the fd can lose writes; send shutdown and wait + * for them to close (set alarm just in case!) */ + alarm(30); + + if (shutdown(peer_fd, SHUT_WR) != 0) + err(1, "failed to shutdown write to peer: %s", strerror(errno)); + + while (sync_crypto_read(NULL, peer_fd, cs)); exit(0); }