Recover P2P and Relay peer connections immediately after Android network handover #7273
Unanswered
hchengting
asked this question in
Issue Triage
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Before posting
Affected area
Client / Agent, Mobile app, Peer connectivity, Relay / Signal / NAT traversal
Deployment type
Self-hosted - quickstart script
Operating system or environment
Linux, Android
NetBird version and upgrade status
Did this work before?
No, this never worked
Regression details
No response
Summary
When an Android client switches between Wi-Fi and mobile data, peer connections
can remain logically connected even though their sockets belong to the previous
network and can no longer carry traffic.
The Android device already has a usable network again, and Management, Signal,
or Relay infrastructure connections may have recovered, but traffic to the peer
remains unavailable until the peer transport detects the failure through its
normal timeout path.
The client should proactively invalidate peer transports bound to the previous
network and rebuild them as soon as the required infrastructure is ready.
Current behavior
Direct P2P/ICE
After Android changes its default network, the ICE sockets created on the old
network can silently become unusable.
The ICE agent can continue reporting the session as connected until its
disconnected and failed timeouts expire. Peer traffic remains unavailable
during this interval even though Signal connectivity has already recovered.
NetBird Relay
When the active peer path uses NetBird Relay, the Relay server connection may
reconnect on the new network before the per-peer Relay connection becomes
usable again.
In testing, peer traffic remains unavailable for approximately 10 additional
seconds after the network transition. Recovery depends on the normal Relay
disconnect callback, connectivity guard, and offer/answer retry flow instead of
being triggered directly by the OS network-change event.
Expected behavior
After Android switches between Wi-Fi and mobile data:
ready on the new network.
timeouts.
unavailable.
Steps to reproduce
Direct P2P
Wi-Fi.
longer usable.
Relay
additional seconds.
Environment and topology
Self-hosted details, if available
No response
Logs, status output, or debug evidence
Related issues or discussions
Impact
moves between Wi-Fi and mobile data
connection manually
Additional context
Cause
The OS network-change notification currently restores infrastructure
connectivity, but peer transports can retain state created on the previous
network.
For ICE:
invalidated.
For Relay:
that every per-peer Relay connection has been retired and recreated.
sending a fresh offer.
Proposed solution
Propagate the Android network-change event to every open peer connection and
invalidate all network-bound peer transports.
ICE handling
For each ICE worker:
session.
Closing the agent must not happen while holding a lock used by its final state
callback.
Relay handling
For each peer Relay connection:
network generation.
connection.
locks.
connection priority.
endpoint and remove only the stale Relay fallback.
open a new per-peer Relay connection.
The same flow must work when Relay is the only available transport.
All reactions