Guard test backend ready channel against double close - #6363
Merged
Conversation
The OnRegisterSession hook fires once per registered session, but TestCreateMCPClient_ContinuousListeningGatedOnSink shares one backend across two parallel subtests that each connect a client. The second registration closed an already-closed channel, panicking and taking the whole test binary down — so the failure surfaced against whichever unrelated test happened to be running. Closes stacklok#6362 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
jhrozek
requested review from
ChrisJBurns,
JAORMX,
amirejaz,
jerm-dro and
tgrunnagle
as code owners
August 18, 2026 14:39
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6363 +/- ##
==========================================
+ Coverage 72.97% 73.04% +0.06%
==========================================
Files 742 742
Lines 78398 78491 +93
==========================================
+ Hits 57208 57330 +122
+ Misses 17201 17153 -48
- Partials 3989 4008 +19 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
JAORMX
approved these changes
Aug 18, 2026
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
TestCreateMCPClient_ContinuousListeningGatedOnSinkshares onelistChangedTestBackendacross twot.Parallel()subtests, each of which connects its own MCP client. The backend'sOnRegisterSessionhook did an unguardedclose(b.ready)— but that hook fires once per registered session, not once per backend. When both clients registered, the channel was closed twice and the test binary died withpanic: close of closed channel.Because the panic aborts the whole binary, it surfaced as a failure of whatever unrelated test happened to be mid-run —
TestInitAndQueryCapabilities_FatalErrors,TestParsingMiddlewareWithRealMCPClients, apkg/ignoretest — which made it look like several different flakes rather than one bug.The fix guards the close with a
sync.Once, so the helper is correct no matter how many sessions register. The alternative (give each subtest its own backend) fixes this call site but leaves the helper fragile for the next test that shares one.Closes #6362
Type of change
Test plan
Reproduced first, then verified the fix. The panic needs varied
GOMAXPROCS; it does not fire at default parallelism.Before (fires within ~3 iterations):
After: 4 ×
-count=40 -cpu=1,2,8(480 runs) all green. A separate 720-run check during investigation was also clean.Plain
-count=60at default-cpustayed green both before and after, which is why this only showed up on CI runners.Does this introduce a user-facing change?
No — test-only change.
Generated with Claude Code