Skip to content

test(storage): fix flaky minimemcached nil-pointer panic#4301

Open
reinkrul wants to merge 2 commits into
masterfrom
fix-flaky-memcached-test
Open

test(storage): fix flaky minimemcached nil-pointer panic#4301
reinkrul wants to merge 2 commits into
masterfrom
fix-flaky-memcached-test

Conversation

@reinkrul
Copy link
Copy Markdown
Member

@reinkrul reinkrul commented Jun 2, 2026

Problem

The storage test job intermittently fails with a panic, crashing the whole test binary:

panic: runtime error: invalid memory address or nil pointer dereference
  github.com/daangn/minimemcached.(*MiniMemcached).serve()  minimemcached.go:125

Root cause

minimemcached.Run synchronously creates the listener, then spawns a goroutine that loops on m.l.Accept(). Close() (called from t.Cleanup) sets that listener to nil. On very short tests the cleanup's Close() can run before the goroutine reaches Accept(), so m.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 guarantees serve() is parked inside Accept() before the test proceeds, so the cleanup Close() unblocks it via listener.Close() cleanly instead of racing goroutine startup.

Verification

go test ./storage/ -run Memcached -count=10 -race passes.

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
@qltysh
Copy link
Copy Markdown
Contributor

qltysh Bot commented Jun 2, 2026

Qlty


Coverage Impact

⬆️ Merging this pull request will increase total coverage on master by 0.02%.

🚦 See full report on Qlty Cloud »

🛟 Help
  • Diff Coverage: Coverage for added or modified lines of code (excludes deleted files). Learn more.

  • Total Coverage: Coverage for the whole repository, calculated as the sum of all File Coverage. Learn more.

  • File Coverage: Covered Lines divided by Covered Lines plus Missed Lines. (Excludes non-executable lines including blank lines and comments.)

    • Indirect Changes: Changes to File Coverage for files that were not modified in this PR. Learn more.

Reference daangn/minimemcached#14 (fix in PR
#13) so the workaround can be removed once an upstream release ships the
fix.

Assisted by AI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant