Skip to content

fix: reset outbound connections on network handover - #122

Open
Vim-01 wants to merge 1 commit into
throneproj:mainfrom
Vim-01:fix/network-handover-reset
Open

Vim-01 wants to merge 1 commit into
throneproj:mainfrom
Vim-01:fix/network-handover-reset

Conversation

@Vim-01

@Vim-01 Vim-01 commented Oct 30, 2026

Copy link
Copy Markdown

Summary

Fixes traffic stall when switching between Wi-Fi and mobile data on Android 15/16 (#114).

Root Cause

  1. LinkProperties for a newly acquired network can be null or empty during the initial onAvailable() callback. The previous logic returned early when interface name was unresolved, failing to reset outbound sockets.
  2. Thread.sleep(100) inside the network callback blocked the connectivity looper, delaying subsequent network capability and link property updates.
  3. Lack of debouncing allowed rapid interface flapping to trigger repeated resets and race conditions in core connection pools.

Solution

  • Track interface reporting state with hasReportedAtLeastOnce to reliably trigger reset when transitioning between active network interfaces.
  • Remove thread sleep from the network callback; register onLinkPropertiesChanged in DefaultNetworkListener to handle asynchronous link updates cleanly.
  • Add a 1500ms debounce to prevent socket churn during brief connectivity transitions.
  • Guard setUnderlyingNetworks with API level check (API 29+) in VpnService.
  • Add unit tests covering clean start, direct handover, break-before-make transitions, and signal flapping.

When switching networks (e.g. Wi-Fi to cellular or vice-versa), outbound connections would stall because clearInterface() reset state.name to null, causing subsequent interface updates to evaluate changed as false. As a result, onDefaultInterfaceChanged was never invoked and proxy core connections remained bound to dead sockets.

- Track initial reporting state per listener so handovers after a disconnect are recognized as network changes.
- Avoid blocking the Looper callback thread on LinkProperties lookup and handle link property updates via onLinkPropertiesChanged.
- Update underlying network state and notify VpnService unconditionally, safely clearing underlying networks when disconnected.
- Add debounce to prevent connection reset storms during rapid signal flapping.
- Add unit test verifying interface state transitions and handover resets.
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