Repository navigation
Conversation
Signed-off-by: kediyalua <kediyalua@outlook.com>
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
cachedDNS.Close()does not actually stop the background refresh goroutine.Close()callstime.Ticker.Stop(), butStop()does not closeTicker.C. The refresh goroutine loops withfor range cdns.refresher.C, which therefore blocks forever afterClose()and leaks. This affects the daemon (wherecdnsis used viadefer cdns.Close(), e.g.main.go) and, more visibly, the test suite, which constructs and cleans up acachedDNSin many tests (setup_test.go,main_test.go).Fix
done chan struct{}and drive the worker with aselectonrefresher.Canddoneinstead offor range refresher.C.Close()closedone(once, viasync.Once) andWait()on async.WaitGroup, so it reliably stops and joins the worker.Close()stays safe to call multiple times (idempotent).Test plan
TestCachedDNS_CloseStopsRefreshGoroutine(packagemain, white-box). It uses a 1-hour refresh interval so the worker is parked waiting on the ticker, then asserts:Close()returns promptly,sync.WaitGroupthe code uses — deterministic, noruntime.NumGoroutine()),Close()is idempotent.go test -run TestCachedDNS_CloseStopsRefreshGoroutine .passes; a negative variant (omittingclose(done)) fails, confirming the test catches the bug.Changelog
CHANGELOG.mdunder## [Unreleased]→### Fixed: "stop the cached DNS refresh goroutine onClose()to avoid leaking a goroutine".Closes #NNNN