fix: handle closed listener cleanly in accept loop - #2691
Open
yuhuayang-google wants to merge 1 commit into
Open
yuhuayang-google wants to merge 1 commit into
yuhuayang-google wants to merge 1 commit into
Conversation
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 #2372
Problem
When the proxy receives a shutdown signal (e.g. SIGTERM/SIGINT) or socket listeners are closed during shutdown,
s.Accept()returnsnet.ErrClosed(use of closed network connection). Previously,serveSocketMounttreated this error as an unhandled failure and returned it.Serve()forwarded it toexitCh, which was then passed toshutdownCh <- err. This caused the proxy to logThe proxy has encountered a terminal error: accept tcp ...: use of closed network connectionand exit with error code 1 or 2 instead of the appropriate exit code 143 (or 0).Solution
serveSocketMount, treatnet.ErrClosed(and errors containing"use of closed network connection") as a clean termination and returnnil.Serve(), wait on all mount goroutines using async.WaitGroupand select onctx.Done()andexitCh, ensuring clean shutdown when mounts close without deadlock.cmd/root.go, only forward non-nil errors fromp.ServetoshutdownCh, and avoid logging terminal error iferr == nil.TestServeExitsCleanlyOnCloseininternal/proxy/proxy_test.goto ensureServereturnsnilwhen the client is closed.