Skip to content

Fix battery drain from busy-polling the incoming packet queue - #11

Merged
damnurmum merged 1 commit into
damnurmum:mainfrom
Eldrinn-Elantey:fix/tun-read-blocking
Oct 7, 2026
Merged

damnurmum merged 1 commit into
damnurmum:mainfrom
Eldrinn-Elantey:fix/tun-read-blocking

Conversation

@Eldrinn-Elantey

Copy link
Copy Markdown

Summary

writeIncomingPackets polled Mobile.read() with a 2 ms sleep, so the tunnel woke the CPU about 500 times a second even with no traffic. With the tunnel on, the phone lost about 30% battery in two hours. The loop now uses Mobile.readTimeout(1000), which blocks on the core's arrived channel and returns as soon as a packet is queued. The 2 ms sleep stays as a fallback for the case where readTimeout returns at once before the core starts.

After the fix, the same phone with the tunnel on and the screen off went from 95% to 85% in about 6 hours.

Verification

  • go test ./...
  • go vet ./...
  • git diff --check
  • Android build/device test, if applicable
  • No URLs, secrets, server addresses, binaries or signing keys are included

Protocol and security impact

None. Packet latency stays the same since readTimeout wakes on arrival.

@damnurmum
damnurmum merged commit b306000 into damnurmum:main Oct 7, 2026
@Eldrinn-Elantey
Eldrinn-Elantey deleted the fix/tun-read-blocking branch October 7, 2026 20:53
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.

2 participants