Skip to content

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

Merged
reinkrul merged 2 commits into
masterfrom
fix-flaky-memcached-test
Jun 4, 2026
Merged

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

Conversation

@reinkrul

@reinkrul reinkrul commented Jun 2, 2026

Copy link
Copy Markdown
Member

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

qltysh Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

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

@stevenvegt stevenvegt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this workaround once a minimemcached release includes the upstream fix.

How do we know this?

@reinkrul

reinkrul commented Jun 4, 2026

Copy link
Copy Markdown
Member Author

Remove this workaround once a minimemcached release includes the upstream fix.

How do we know this?

We don't, I'm subscribed to the issue, so I'll get a notification. And we link to it in the source code, + we get dependency updates through dependabot (so check changelog).

@reinkrul
reinkrul merged commit 3fc83ee into master Jun 4, 2026
12 checks passed
@reinkrul
reinkrul deleted the fix-flaky-memcached-test branch June 4, 2026 07:46
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.

2 participants