Repository navigation
Fix daemon races when tunnels are opened and closed concurrently - #49
Merged
Merged
Conversation
alebeck
force-pushed
the
fix/daemon-concurrency
branch
from
October 4, 2026 15:54
38d12db to
c5f79c0
Compare
alebeck
force-pushed
the
fix/daemon-concurrency
branch
from
October 4, 2026 17:29
c5f79c0 to
3bef6c3
Compare
alebeck
force-pushed
the
fix/daemon-concurrency
branch
from
October 4, 2026 17:41
3bef6c3 to
ab65e51
Compare
This was referenced Oct 5, 2026
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.
Fixes races in the daemon that show up when the same tunnel is opened or closed by several clients at once, plus data races in the tunnel code flagged by
-race.Closeonly checkedStatus, which staysOpenuntil the run loop has shut the tunnel down. Two clients closing the same tunnel could both close the stop channel, panicking withclose of closed channeland taking down every tunnel. The stop channel is now closed through async.Once.address already in use. Every client got past the "already running" check. Concurrent opens of a tunnel now share a single attempt throughsingleflight: the other clients report the tunnel as already running, or get the same error if the attempt failed.StatusandLastConn. They were written by the tunnel goroutines and read by the daemon forlist. They are now guarded by a mutex inTunnel, and the daemon lists tunnels throughSnapshot.Addwas called inside the new goroutine, racing withWait.goWait(formerlywaitFor) now callsAddbefore starting the goroutine.closeresponds.closeTunnelnow removes the tunnel itself instead of leaving it to the closing goroutine, so a reopen right afterclosecan never find the old entry and be rejected as already running. Since a tunnel is now removed in two places, removal checks that it is still the same tunnel, so it never drops one that was reopened under the same name.Testing
mainthey reproduce the daemon panic and theaddress already in usefailures.Tunnel.Close,Snapshotand tunnel removal.-race, the daemon logs 24 data races during the e2e suite onmainand none with this change.make testpasses.Changes during review
Rebased onto
main(after #48) and squashed. The name reservation in the daemon was replaced withsingleflightfromgolang.org/x/sync(already a dependency), so waiting clients share a failed attempt instead of retrying one after another.listStatusis now shared withwaitForStatus, and single CLI runs in the e2e tests use a newmustRunhelper.