Skip to content

fix: stop VPN core when signaling auth fails - #3

Merged
Warexpor merged 1 commit into
masterfrom
cursor/fix-signaling-auth-lifecycle-c911
Aug 29, 2026
Merged

fix: stop VPN core when signaling auth fails#3
Warexpor merged 1 commit into
masterfrom
cursor/fix-signaling-auth-lifecycle-c911

Conversation

@Warexpor

Copy link
Copy Markdown
Owner

Problem

1.3.0 made VPNCore.Start() wait for signaling auth (authOK / authErr / 15s timeout). connectSignaling() assigns v.signaling and opens the WebSocket before that wait. On auth failure or timeout, Start() returned the error without closing signaling.

App.Connect then wired and assigned a.vpn = newVPN, called newVPN.Start(), and on error only niled a.vpn if it still pointed at that core. It never called newVPN.Stop().

The live SignalingClient (and wired callbacks) survived a failed Connect. Disconnect could not clean it up because a.vpn was nil. Retrying Connect stacked more zombie sessions. OnDisconnected on an orphaned core could also start reconnectLoop.

reconnectLoop had the same hole: after connectSignaling() succeeded, auth failure/timeout continued without closing that attempt’s WebSocket, so the next try opened another one.

Fix

  1. client/app.go Connect — if newVPN.Start() fails, nil a.vpn when it still points at newVPN, then call newVPN.Stop(). opMu is unchanged.
  2. client/vpncore/vpn.go Start — on auth error or auth timeout, call Stop() before returning so signaling, TUN, and peers tear down. Stop also nils v.signaling so room ops fail with “not connected” instead of talking to a closed socket.
  3. reconnectLoop — on auth failure or timeout, closeSignalingAttempt() closes and nils that try’s signaling before continue. That helper does not set stopping, so reconnect can still retry.

Test

client/vpncore/lifecycle_test.go now drives a local WebSocket that rejects auth. Start must fail, the server must drop to zero live connections, and CreateRoom/JoinRoom must still fail. A second case checks that Stop after a failed dial is safe to call twice.

No version bump, changelog, or UI changes.

Open in Web Open in Cursor 

1.3.0 waited on signaling auth in Start() after opening the
WebSocket, but auth failure or timeout returned without closing it.
Connect then dropped the core without Stop(), so zombie sessions
survived retries. Close that attempt on Start and reconnectLoop,
and Stop the core when Connect fails.

Co-authored-by: Warexpor <warexpor@gmail.com>
@Warexpor
Warexpor marked this pull request as ready for review August 29, 2026 10:14
@Warexpor
Warexpor merged commit 7214a63 into master Aug 29, 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