@@ -223,9 +223,8 @@ impl BackgroundProcessor {
223223 channel_manager. process_pending_events ( & event_handler) ;
224224 chain_monitor. process_pending_events ( & event_handler) ;
225225
226- // We wait up to 100ms, but on a mobile device without a ton of activity, if we get
227- // put in the background and paused, this is likely where it will happen, causing
228- // the wait time to be substantially longer.
226+ // We wait up to 100ms, but track how long it takes to detect being put to sleep,
227+ // see `await_start`'s use below.
229228 let await_start = Instant :: now ( ) ;
230229 let updates_available =
231230 channel_manager. await_persistable_update_timeout ( Duration :: from_millis ( 100 ) ) ;
@@ -246,14 +245,14 @@ impl BackgroundProcessor {
246245 channel_manager. timer_tick_occurred ( ) ;
247246 last_freshness_call = Instant :: now ( ) ;
248247 }
249- if await_time > Duration :: from_secs ( 1 ) {
248+ if await_time. as_secs ( ) > 2 * PING_TIMER {
250249 // On various platforms, we may be starved of CPU cycles for several reasons.
251250 // E.g. on iOS, if we've been in the background, we will be entirely paused.
252251 // Similarly, if we're on a desktop platform and the device has been asleep, we
253252 // may not get any cycles.
254253 // In any case, if we've been entirely paused for more than double our ping
255254 // timer, we should have disconnected all sockets by now (and they're probably
256- // dead anyway), so disconnect them by calling `timer_tick_occurred()` twice .
255+ // dead anyway).
257256 // Note that we have to take care to not get here just because user event
258257 // processing was slow at the top of the loop. For example, the sample client
259258 // may call Bitcoin Core RPCs during event handling, which very often takes
0 commit comments