fix(relay): prevent panic on double Stop() of UDPProxyServer (#51) - #105
Open
Adityakk9031 wants to merge 1 commit into
Open
fix(relay): prevent panic on double Stop() of UDPProxyServer (#51)#105Adityakk9031 wants to merge 1 commit into
Adityakk9031 wants to merge 1 commit into
Conversation
The UDPProxyServer.Stop() method was being called twice on every clean shutdown — once via defer proxyRelay.Stop() in main() and once from the shutdown errgroup goroutine — causing a 'close of closed channel' panic. The old guard using a bare select on s.ctx.Done() was ineffective: by the second call the context was already cancelled, so both code paths fell through unconditionally to close(s.packetChan), panicking. Fix: wrap the entire Stop() body in a sync.Once so that all cleanup (cancel, conn close, packetChan close) runs at most once regardless of how many times or from how many goroutines Stop() is called. Fixes fosrl#51
Adityakk9031
requested review from
miloschwartz and
oschwartz10612
as code owners
July 21, 2026 12:19
Author
|
@oschwartz10612 and @miloschwartz have a look |
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.
Summary
Fixes #51
Gerbil was panicking with
panic: close of closed channelon every cleanshutdown (and sometimes randomly during operation). The process would then
restart via Docker's restart policy, re-register with Pangolin, and resume —
but left some resources in a broken state requiring manual intervention.
Root Cause
UDPProxyServer.Stop()was being called twice on every shutdown:defer proxyRelay.Stop()main.go:533main()returnsproxyRelay.Stop()main.go:606groupCtxis cancelled (shutdown signal)Both fire on every clean exit. The second call panicked because
close(s.packetChan)was executed twice.The existing guard was ineffective: