From d58e6fa20b2a9ecc7beeea6a441e3281086de367 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sat, 16 Jul 2022 14:19:30 +0930 Subject: [PATCH] lightningd: don't tell connectd to disconnect peer if it told us. We allow connectd to tell us a peer has gone away, but now we need to make sure we don't double-spiderman and tell it to disconnect peer. This is particularly harmful on reconnect: it (will soon) tell us the old connection is gone, ready to tell us the new peer has connected. We would tell it to disconnect the peer, which throws away the new connection! Signed-off-by: Rusty Russell --- lightningd/connect_control.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lightningd/connect_control.c b/lightningd/connect_control.c index 842fe8a28..b48a2310f 100644 --- a/lightningd/connect_control.c +++ b/lightningd/connect_control.c @@ -668,8 +668,11 @@ void maybe_disconnect_peer(struct lightningd *ld, struct peer *peer) return; } - subd_send_msg(ld->connectd, - take(towire_connectd_discard_peer(NULL, &peer->id))); + /* If connectd was the one who told us to cleanup peer, don't + * tell it to discard again: it might have reconnected! */ + if (peer->is_connected) + subd_send_msg(ld->connectd, + take(towire_connectd_discard_peer(NULL, &peer->id))); } static struct command_result *json_sendcustommsg(struct command *cmd,