From 77b1087cdfaadd5b957a58e1bc13d964a71d28ae Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 23 Mar 2022 06:56:30 +1030 Subject: [PATCH] lightningd: move notification of disconnect into when we hear from connectd. Simpler, and closes a potential race. Signed-off-by: Rusty Russell --- lightningd/dual_open_control.c | 2 -- lightningd/opening_common.c | 1 - lightningd/peer_control.c | 5 +++-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lightningd/dual_open_control.c b/lightningd/dual_open_control.c index f10fffe9b..8ccfd0634 100644 --- a/lightningd/dual_open_control.c +++ b/lightningd/dual_open_control.c @@ -46,8 +46,6 @@ static void channel_disconnect(struct channel *channel, log_(channel->log, level, NULL, false, "%s", desc); channel_cleanup_commands(channel, desc); - notify_disconnect(channel->peer->ld, &channel->peer->id); - if (!reconnect) channel_set_owner(channel, NULL); else diff --git a/lightningd/opening_common.c b/lightningd/opening_common.c index 1b5551a2a..21bc0fb84 100644 --- a/lightningd/opening_common.c +++ b/lightningd/opening_common.c @@ -110,7 +110,6 @@ void uncommitted_channel_disconnect(struct uncommitted_channel *uc, subd_send_msg(uc->peer->ld->connectd, msg); if (uc->fc && uc->fc->cmd) was_pending(command_fail(uc->fc->cmd, LIGHTNINGD, "%s", desc)); - notify_disconnect(uc->peer->ld, &uc->peer->id); } diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 35a90791f..e3bfd1ca0 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -293,8 +293,6 @@ void channel_errmsg(struct channel *channel, bool warning, const u8 *err_for_them) { - notify_disconnect(channel->peer->ld, &channel->peer->id); - /* Clean up any in-progress open attempts */ channel_cleanup_commands(channel, desc); @@ -1267,6 +1265,9 @@ void peer_disconnect_done(struct lightningd *ld, const u8 *msg) if (p) p->is_connected = false; + /* Fire off plugin notifications */ + notify_disconnect(ld, &id); + /* Wake any disconnect commands (removes self from list) */ list_for_each_safe(&ld->disconnect_commands, i, next, list) { if (!node_id_eq(&i->id, &id))