fix: stop retrying on local socket exhaustion - #3062
Open
nakamotoliu wants to merge 1 commit into
Open
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.
Summary
Stop the tunnel dial retry loop immediately when the local host reports socket resource exhaustion, including
EADDRNOTAVAIL.Root cause
tunnel.retrycurrently attempts most failed dials up to 10 times. Local resource exhaustion is not transient on the retry loop's millisecond-to-second time scale. RetryingEADDRNOTAVAIL,EMFILE,ENFILE, orENOBUFScannot free the exhausted resource and may amplify an existing connection storm.In one macOS TUN incident, the IPv4 ephemeral port range contained 16,384 ports while the host had approximately 16,477 TCP sockets in
TIME_WAIT. IPv4 loopback connections then failed with errno 49 /EADDRNOTAVAIL, even though the local services were still listening. Multiple rule providers and health checks continued dialing through the same retry path.Changes
Impact
This does not attempt to repair an already exhausted OS socket table. It prevents Mihomo from multiplying each failed dial into up to 10 attempts, reducing the chance that a degraded network state escalates into complete local IPv4 connection failure.
Validation
go vet ./tunnelgo test ./tunnel -count=1GOTOOLCHAIN=go1.20.14 go test ./tunnel -count=1SKIP_INTEROP_TEST=1 go test ./... -count=1SKIP_INTEROP_TEST=1 go test ./... -tags with_gvisor -count=1tunneltest binary for Darwin/arm64, Linux/amd64, and Windows/amd64tunneltest binary with Go 1.20.14Related downstream report: clash-verge-rev/clash-verge-rev#7532