upstream: fix connection pool leak#497
Open
fakhriaunur wants to merge 1 commit intoAdguardTeam:masterfrom
Open
upstream: fix connection pool leak#497fakhriaunur wants to merge 1 commit intoAdguardTeam:masterfrom
fakhriaunur wants to merge 1 commit intoAdguardTeam:masterfrom
Conversation
Fix CLOSE_WAIT connection leak in DNS-over-TLS. Add connection validation before reusing connections from pool to prevent accumulation of stale connections in CLOSE_WAIT state. Fixes AdguardTeam#444 Changes: - Add isConnAlive() helper for connection validation - Validate connections in getConn() before reuse - Close and discard dead connections - Add table-driven tests with race detection - Coverage: 85.7% for modified functions Tested: - go test ./upstream/ - PASS - go test -race ./upstream/ - PASS (no races) - go vet ./upstream/ - PASS
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
Fix CLOSE_WAIT connection leak in DNS-over-TLS connection pool.
The DoT connection pool stores connections in a slice and reuses them without validation. Over time, stale connections accumulate in
CLOSE_WAITstate, leading to connection leaks and degraded performance (as noted in the TODO comment indot.go:47-51).Changes
isConnAlive()helper function to validate connection healthgetConn()to validate connections before reuseTestIsConnAlivetests for connection validationRoot Cause
The TODO comment in
dot.go:47-51acknowledges this issue:Testing
Code Change Statistics
Technical Details
The fix uses a non-blocking read with a short deadline (10ms) to check connection health without affecting normal operation. Dead connections are closed and removed from the pool, preventing CLOSE_WAIT accumulation.
Issues
Fixes #444
Checklist
go test ./upstream/)go test -race ./upstream/)go vet ./upstream/)Note: This fix is minimal and targeted. It doesn't redesign the connection pool (which would be a larger change) but adds validation to prevent CLOSE_WAIT accumulation.