Skip to content

Commit 0c6637e

Browse files
committed
Handle being asleep for more than double our ping time gracefully
If we've been asleep for double our ping time, for whatever reason, disconnect all open sockets.
1 parent 736ec06 commit 0c6637e

File tree

1 file changed

+13
-1
lines changed
  • lightning-background-processor/src

1 file changed

+13
-1
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,19 @@ impl BackgroundProcessor {
161161
channel_manager.timer_tick_occurred();
162162
last_freshness_call = Instant::now();
163163
}
164-
if last_ping_call.elapsed().as_secs() > PING_TIMER {
164+
if last_ping_call.elapsed().as_secs() > PING_TIMER * 2 {
165+
// On various platforms, we may be starved of CPU cycles for several reasons.
166+
// E.g. on iOS, if we've been in the background, we will be entirely paused.
167+
// Similarly, if we're on a desktop platform and the device has been asleep, we
168+
// may not get any cycles.
169+
// In any case, if we've been entirely paused for more than double our ping
170+
// timer, we should have disconnected all sockets by now (and they're probably
171+
// dead anyway), so disconnect them by calling `timer_tick_occurred()` twice.
172+
log_trace!(logger, "Awoke after more than double our ping timer, disconnecting peers.");
173+
peer_manager.timer_tick_occurred();
174+
peer_manager.timer_tick_occurred();
175+
last_ping_call = Instant::now();
176+
} else if last_ping_call.elapsed().as_secs() > PING_TIMER {
165177
log_trace!(logger, "Calling PeerManager's timer_tick_occurred");
166178
peer_manager.timer_tick_occurred();
167179
last_ping_call = Instant::now();

0 commit comments

Comments
 (0)