Skip to content

fix(wgbridge): rebind UDP sockets to a fresh ephemeral port - #999

Merged
kasnder merged 1 commit into
masterfrom
claude/sleepy-wright-2z76m6
Oct 25, 2026
Merged

kasnder merged 1 commit into
masterfrom
claude/sleepy-wright-2z76m6

Conversation

@kasnder

@kasnder kasnder commented Oct 25, 2026

Copy link
Copy Markdown
Member

Why CI failed

The instrumentation job on master (run 39949143135) failed in WgbridgeInstrumentedTest.tunnelStatsRebindAndStopUseRealJni:

java.lang.RuntimeException: Failed to bind UDP sockets (params=UdpTransportFactoryParams { addr: None, port: 34044 }): Address already in use (os error 98)
	at net.kollnig.missioncontrol.wgbridge.Tunnel.nativeRebind(Native Method)

The gotatun 0.9.2 → 0.10.1 bump (#989) changed Connection::set_up to remember the port it actually bound (device.port = addr.port()). Tunnel::rebind() toggled the port and then restored the original value, which is now that concrete port, not 0. The new socket is bound to the same port while the old one may still be held by connection tasks that are shutting down, so the bind fails intermittently. The same PR's own run passed, so this is a race and not something #997 introduced.

Change

rebind() now always ends on port 0, so each rebind gets a fresh ephemeral port. TrackerControl never configures a listen port, and WireGuard peers roam to the new source port on the next packet. This affects production roaming as well as the test.

Testing

  • cargo test in wgbridge-rs: 71 passed.
  • The instrumented test needs an emulator, so it will be verified by this PR's CI.

https://claude.ai/code/session_012jPc9ojxUPCR3f3hR4ycTP


Generated by Claude Code

gotatun 0.10 records the port it actually bound, so Tunnel::rebind()
restored that concrete port and re-bound it while the old socket could
still be held by tasks that were shutting down. This failed
intermittently with EADDRINUSE, as in the instrumented test
tunnelStatsRebindAndStopUseRealJni on master. End the toggle on port 0
instead so each rebind gets a fresh ephemeral port.

Claude-Session: https://claude.ai/code/session_012jPc9ojxUPCR3f3hR4ycTP
@kasnder
kasnder marked this pull request as ready for review October 25, 2026 22:43
@kasnder
kasnder merged commit 78b1ed2 into master Oct 25, 2026
3 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.

2 participants