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