Skip to content

Slow the WG connectivity watchdog when the screen is off - #749

Merged
kasnder merged 1 commit into
masterfrom
wg-monitor-idle-cadence
Aug 22, 2026
Merged

Slow the WG connectivity watchdog when the screen is off#749
kasnder merged 1 commit into
masterfrom
wg-monitor-idle-cadence

Conversation

@kasnder

@kasnder kasnder commented Aug 21, 2026

Copy link
Copy Markdown
Member

Problem

WgConnectivityMonitor polls the tunnel's transfer counters every second for as long as the WireGuard tunnel runs — including overnight with the screen off. The monitor is fully passive (counter reads over JNI; it never wakes the radio and holds no wakelock), but each poll still costs a CPU wake, so a healthy idle tunnel burned one wakeup per second between screen-off and deep doze. Its purpose is catching stalls while traffic flows, which overwhelmingly happens with the screen on.

Change

  • Poll every 1s while interactive, 15s while the screen is off (WgConnectivityMonitor.pollIntervalMs). The cadence is sampled each iteration from a new isInteractive supplier, backed by WgEgress.currentInteractive (now @Volatile, since the monitor thread reads it).
  • Scale the doze-detection threshold with the active interval (isSuspendGap): a gap past one full cycle + 5s margin means doze. This preserves the previous fixed 6s threshold at the 1s cadence and prevents the normal 15s background cycle from being mistaken for a suspension.
  • No behaviour change otherwise: stall detection, prod, restart backoff, and onSuspended rebasing are untouched. Background sync still gets stall detection within one 15s cycle.

Testing

  • New WgConnectivityMonitorTest: cadence mapping, threshold preserved at 6s on the interactive cadence, threshold scales past the idle cadence without false suspend detection.
  • WgConnectivityCheckerTest and WgEgressRecoveryTest pass unmodified.

The liveness monitor polled tunnel counters every second for as long as
the tunnel ran, including overnight with the screen off — a CPU wake per
second for hours, for a watchdog whose purpose is catching stalls while
traffic flows. Poll at 15s instead while the screen is off (1s when
interactive), and scale the doze-detection gap threshold with the active
interval so the slow cadence is not mistaken for a suspension.
@kasnder
kasnder merged commit 197d404 into master Aug 22, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant