Repository navigation
[bugfix] reconnect: fix zombie VPN when TUN fails to reopen - #277
Merged
Merged
Conversation
On reconnect the server assigns a new client IP, which makes VpnManager::HandleOnIPAssignedCallback rebuild the tunnel: Stop() the TUN, Clean() routes, Start() the TUN, Apply() routes. The result of Start() was ignored, so when the TUN failed to reopen -- on Windows the Wintun adapter from the previous connection is often not released yet -- routes were applied over a dead device and all traffic black-holed. IsStarted() only checked the WebSocket, so the tray icon stayed green: "connected" but nothing works until a manual reconnect (which releases the adapter first). - Retry the TUN open a few times with a short delay to win the adapter release race. - If it still fails, skip route setup and leave the connection marked down so it tears down and reconnects instead of black-holing traffic. - Gate IsStarted() on a new tun_alive_ flag so a dead tunnel is reported as disconnected, never a green zombie. Reproduced from a Windows 0.4.0 GUI log: the 06:00 reconnect reopened the WebSocket, logged "Failed to open TUN device", applied routes anyway, and reported "Routing setup completed successfully" -> green icon, no traffic.
batchar2
force-pushed
the
bugfix/reconnect-tun-zombie
branch
3 times, most recently
from
June 3, 2026 02:39
7b8eee3 to
9e526ab
Compare
batchar2
force-pushed
the
bugfix/reconnect-tun-zombie
branch
from
June 3, 2026 04:51
9e526ab to
96983f5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On reconnect the server assigns a new client IP, which makes VpnManager::HandleOnIPAssignedCallback rebuild the tunnel: Stop() the TUN, Clean() routes, Start() the TUN, Apply() routes. The result of Start() was ignored, so when the TUN failed to reopen -- on Windows the Wintun adapter from the previous connection is often not released yet -- routes were applied over a dead device and all traffic black-holed. IsStarted() only checked the WebSocket, so the tray icon stayed green: "connected" but nothing works until a manual reconnect (which releases the adapter first).
Reproduced from a Windows 0.4.0 GUI log: the 06:00 reconnect reopened the WebSocket, logged "Failed to open TUN device", applied routes anyway, and reported "Routing setup completed successfully" -> green icon, no traffic.