Skip to content

[bugfix] reconnect: fix zombie VPN when TUN fails to reopen - #277

Merged
batchar2 merged 2 commits into
masterfrom
bugfix/reconnect-tun-zombie
Jun 3, 2026
Merged

batchar2 merged 2 commits into
masterfrom
bugfix/reconnect-tun-zombie

Conversation

@pavel-shpilev

Copy link
Copy Markdown
Collaborator

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.

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
batchar2 force-pushed the bugfix/reconnect-tun-zombie branch 3 times, most recently from 7b8eee3 to 9e526ab Compare June 3, 2026 02:39
@batchar2
batchar2 force-pushed the bugfix/reconnect-tun-zombie branch from 9e526ab to 96983f5 Compare June 3, 2026 04:51
@batchar2
batchar2 merged commit 2bd753b into master Jun 3, 2026
5 checks passed
@batchar2
batchar2 deleted the bugfix/reconnect-tun-zombie branch June 3, 2026 07:00
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