From be7a27a765b155c1d3e3b161f4deafbe1abab1db Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 9 Aug 2018 09:58:30 +0930 Subject: [PATCH] connect: randomize backoff a little. Since we now fixed the bug where nodes receiving a connection would try to reconnect to the source IP/port of that connection, we now expose an issue mentioned by other implementers: we can continually cross over reconnections unless we add some fuzz. One second should be sufficient. Signed-off-by: Rusty Russell --- lightningd/connect_control.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lightningd/connect_control.c b/lightningd/connect_control.c index a8faa21a7..cb85f2acf 100644 --- a/lightningd/connect_control.c +++ b/lightningd/connect_control.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -229,7 +230,12 @@ void delay_then_reconnect(struct channel *channel, u32 seconds_delay, log_debug(channel->log, "Will try reconnect in %u seconds", seconds_delay); - notleak(new_reltimer(&ld->timers, d, time_from_sec(seconds_delay), + + /* We fuzz the timer by up to 1 second, to avoid getting into + * simultanous-reconnect deadlocks with peer. */ + notleak(new_reltimer(&ld->timers, d, + timerel_add(time_from_sec(seconds_delay), + time_from_usec(pseudorand(1000000))), maybe_reconnect, d)); }