test(storage): fix flaky minimemcached nil-pointer panic#4301
Open
reinkrul wants to merge 2 commits into
Open
Conversation
The minimemcached test server spawns a goroutine that calls Accept() on its listener, while Close() nils that listener. On very short tests the cleanup's Close() could run before the goroutine entered Accept(), dereferencing a nil listener inside the dependency and crashing the test binary with a panic that no test can recover (it runs in a foreign goroutine). Block in the test helper until the server answers a probe connection, guaranteeing the accept loop is parked in Accept() before the test proceeds. Close() then unblocks it cleanly instead of racing startup. Assisted by AI
Contributor
|
Coverage Impact ⬆️ Merging this pull request will increase total coverage on 🛟 Help
|
Reference daangn/minimemcached#14 (fix in PR #13) so the workaround can be removed once an upstream release ships the fix. Assisted by AI
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.

Problem
The
storagetest job intermittently fails with a panic, crashing the whole test binary:Root cause
minimemcached.Runsynchronously creates the listener, then spawns a goroutine that loops onm.l.Accept().Close()(called fromt.Cleanup) sets that listener tonil. On very short tests the cleanup'sClose()can run before the goroutine reachesAccept(), som.l.Accept()dereferences a nil listener. The panic happens in a dependency-spawned goroutine, so no test can recover it — the binary dies.This is an upstream bug; v1.2.0 is the latest release, so there's no version to bump to.
Fix
Block in the test helper until the server actually answers a probe connection (
version\r\n). That guaranteesserve()is parked insideAccept()before the test proceeds, so the cleanupClose()unblocks it vialistener.Close()cleanly instead of racing goroutine startup.Verification
go test ./storage/ -run Memcached -count=10 -racepasses.