@@ -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