Skip to content

Gate DoH retries and keep-alives on screen state - #747

Open
kasnder wants to merge 1 commit into
masterfrom
fix/doh-screen-off-battery
Open

Gate DoH retries and keep-alives on screen state#747
kasnder wants to merge 1 commit into
masterfrom
fix/doh-screen-off-battery

Conversation

@kasnder

@kasnder kasnder commented Aug 21, 2026

Copy link
Copy Markdown
Member

Screen-off DoH queries used to run the full retry loop and leave an idle TLS keep-alive socket behind after every lookup. During doze a retry is a second radio wakeup for a query that is already failing, and an idle pooled socket can be reset by the server mid-doze, waking the radio (the known screen-off DoH battery issue from AGENTS.md).

What changes

  • DnsOverHttpsClient: new setScreenOff() policy. While the screen is off, resolve() skips retries (MAX_RETRIES -> 0) and evicts the connection pool after each query so nothing idle survives. Screen-on restores retries and normal pooling.
  • DnsProxyServer: onScreenOff() replaced with onScreenStateChanged(interactive); start() syncs the policy so a reload mid-doze doesn't inherit screen-on behaviour.
  • ServiceSinkhole: the interactive-state receiver now pushes both screen transitions to the proxy.
  • The response cache is intentionally preserved - it is most valuable at night, when queries repeat against a dozing device.

Tests

  • DnsOverHttpsClientTest: resolveDoesNotRetryWhenScreenOff asserts a 503 gives up after one request (vs three with the screen on). All 16 tests pass.

Screen-off DoH queries used to run the full retry loop and leave an idle TLS keep-alive socket behind after every lookup. During doze a retry is a second radio wakeup for a query that is already failing, and an idle pooled socket can be reset by the server mid-doze, waking the radio.

While the screen is off: skip retries, and evict the connection pool after each query so nothing idle survives. Screen-on restores retries and normal pooling. The response cache is intentionally preserved - it is most valuable at night, when queries repeat against a dozing device.
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