Skip to content

Commit c779abd

Browse files
committed
connectd: don't run more than one reconnect timer at once.
From grubles' logs: ``` 2025-01-06T15:30:31.449Z DEBUG lightningd: attempting connection to 035ca2fe4793a5e789ce846062eb4834f573c060d9200ce77544a29b48a0aa5923 for additional gossip 2025-01-06T15:30:31.449Z DEBUG 035ca2fe4793a5e789ce846062eb4834f573c060d9200ce77544a29b48a0aa5923-connectd: Adding 0 addresses to important peer 2025-01-06T15:30:31.449Z DEBUG 035ca2fe4793a5e789ce846062eb4834f573c060d9200ce77544a29b48a0aa5923-connectd: Failed connected out: Unable to connect, no address known for peer 2025-01-06T15:30:31.449Z DEBUG 035ca2fe4793a5e789ce846062eb4834f573c060d9200ce77544a29b48a0aa5923-connectd: Will try reconnect in 300 seconds 2025-01-06T15:30:32.037Z DEBUG 035ca2fe4793a5e789ce846062eb4834f573c060d9200ce77544a29b48a0aa5923-connectd: Failed connected out: Unable to connect, no address known for peer 2025-01-06T15:30:32.037Z DEBUG 035ca2fe4793a5e789ce846062eb4834f573c060d9200ce77544a29b48a0aa5923-connectd: Will try reconnect in 300 seconds 2025-01-06T15:30:32.428Z DEBUG 035ca2fe4793a5e789ce846062eb4834f573c060d9200ce77544a29b48a0aa5923-connectd: Failed connected out: Unable to connect, no address known for peer 2025-01-06T15:30:32.428Z DEBUG 035ca2fe4793a5e789ce846062eb4834f573c060d9200ce77544a29b48a0aa5923-connectd: Will try reconnect in 300 seconds 2025-01-06T15:30:32.680Z DEBUG 035ca2fe4793a5e789ce846062eb4834f573c060d9200ce77544a29b48a0aa5923-connectd: Failed connected out: Unable to connect, no address known for peer 2025-01-06T15:30:32.681Z DEBUG 035ca2fe4793a5e789ce846062eb4834f573c060d9200ce77544a29b48a0aa5923-connectd: Will try reconnect in 300 seconds 2025-01-06T15:30:33.468Z DEBUG 035ca2fe4793a5e789ce846062eb4834f573c060d9200ce77544a29b48a0aa5923-connectd: Failed connected out: Unable to connect, no address known for peer 2025-01-06T15:30:33.469Z DEBUG 035ca2fe4793a5e789ce846062eb4834f573c060d9200ce77544a29b48a0aa5923-connectd: Will try reconnect in 300 seconds 2025-01-06T15:30:33.471Z DEBUG 035ca2fe4793a5e789ce846062eb4834f573c060d9200ce77544a29b48a0aa5923-connectd: Failed connected out: Unable to connect, no address known for peer 2025-01-06T15:30:33.471Z DEBUG 035ca2fe4793a5e789ce846062eb4834f573c060d9200ce77544a29b48a0aa5923-connectd: Will try reconnect in 300 seconds 2025-01-06T15:30:33.935Z DEBUG 035ca2fe4793a5e789ce846062eb4834f573c060d9200ce77544a29b48a0aa5923-connectd: Failed connected out: Unable to connect, no address known for peer 2025-01-06T15:30:33.935Z DEBUG 035ca2fe4793a5e789ce846062eb4834f573c060d9200ce77544a29b48a0aa5923-connectd: Will try reconnect in 300 seconds 2025-01-06T15:30:34.125Z DEBUG 035ca2fe4793a5e789ce846062eb4834f573c060d9200ce77544a29b48a0aa5923-connectd: Failed connected out: Unable to connect, no address known for peer 2025-01-06T15:30:34.125Z DEBUG 035ca2fe4793a5e789ce846062eb4834f573c060d9200ce77544a29b48a0aa5923-connectd: Will try reconnect in 300 seconds 2025-01-06T15:30:35.496Z DEBUG 035ca2fe4793a5e789ce846062eb4834f573c060d9200ce77544a29b48a0aa5923-connectd: Failed connected out: Unable to connect, no address known for peer 2025-01-06T15:30:35.497Z DEBUG 035ca2fe4793a5e789ce846062eb4834f573c060d9200ce77544a29b48a0aa5923-connectd: Will try reconnect in 300 seconds 2025-01-06T15:30:35.623Z DEBUG 035ca2fe4793a5e789ce846062eb4834f573c060d9200ce77544a29b48a0aa5923-connectd: Failed connected out: Unable to connect, no address known for peer 2025-01-06T15:30:35.623Z DEBUG 035ca2fe4793a5e789ce846062eb4834f573c060d9200ce77544a29b48a0aa5923-connectd: Will try reconnect in 300 seconds 2025-01-06T15:30:35.751Z DEBUG 035ca2fe4793a5e789ce846062eb4834f573c060d9200ce77544a29b48a0aa5923-connectd: Failed connected out: Unable to connect, no address known for peer 2025-01-06T15:30:35.751Z DEBUG 035ca2fe4793a5e789ce846062eb4834f573c060d9200ce77544a29b48a0aa5923-connectd: Will try reconnect in 300 seconds 2025-01-06T15:30:35.892Z DEBUG 035ca2fe4793a5e789ce846062eb4834f573c060d9200ce77544a29b48a0aa5923-connectd: Failed connected out: Unable to connect, no address known for peer 2025-01-06T15:30:35.892Z DEBUG 035ca2fe4793a5e789ce846062eb4834f573c060d9200ce77544a29b48a0aa5923-connectd: Will try reconnect in 300 seconds ``` We promised to wait 300 seconds! Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 556e38c commit c779abd

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

connectd/connectd.c

+7-5
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,7 @@ static void reconnect(struct important_id *imp)
796796
/* Do gossmap lookup to find any addresses from there, and append. */
797797
append_gossmap_addresses(&addrs, imp->daemon, &imp->id);
798798

799+
imp->reconnect_timer = NULL;
799800
try_connect_peer(imp->daemon, &imp->id, take(addrs), false);
800801
}
801802

@@ -811,7 +812,7 @@ static void schedule_reconnect_if_important(struct daemon *daemon,
811812
return;
812813

813814
/* Already on it? */
814-
if (find_connecting(daemon, id))
815+
if (find_connecting(daemon, id) || imp->reconnect_timer)
815816
return;
816817

817818
/* --dev-no-reconnect? Don't reconnect. */
@@ -822,10 +823,10 @@ static void schedule_reconnect_if_important(struct daemon *daemon,
822823
imp->reconnect_secs);
823824
/* We fuzz the timer by up to 1 second, to avoid getting into
824825
* simultanous-reconnect deadlocks with peer. */
825-
notleak(new_reltimer(&daemon->timers, imp,
826-
timerel_add(time_from_sec(imp->reconnect_secs),
827-
time_from_usec(pseudorand(1000000))),
828-
reconnect, imp));
826+
imp->reconnect_timer = new_reltimer(&daemon->timers, imp,
827+
timerel_add(time_from_sec(imp->reconnect_secs),
828+
time_from_usec(pseudorand(1000000))),
829+
reconnect, imp);
829830

830831
/* Back off next time if that fails */
831832
imp->reconnect_secs *= 2;
@@ -1972,6 +1973,7 @@ static void connect_to_peer(struct daemon *daemon, const u8 *msg)
19721973
struct wireaddr_internal,
19731974
addrs);
19741975
imp->reconnect_secs = INITIAL_WAIT_SECONDS;
1976+
imp->reconnect_timer = NULL;
19751977
tal_add_destructor(imp, destroy_important_id);
19761978
important_id_htable_add(daemon->important_ids, imp);
19771979
} else

connectd/connectd.h

+3
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ struct important_id {
149149

150150
struct node_id id;
151151
struct wireaddr_internal *addrs;
152+
153+
/* Backoff timer (increases by 2 each time) */
152154
size_t reconnect_secs;
155+
struct oneshot *reconnect_timer;
153156
};
154157

155158
static const struct node_id *important_id_keyof(const struct important_id *imp)

0 commit comments

Comments
 (0)