Repository navigation
Conversation
…mission order The test raced two result channels in a select to decide which caller was served first. That measures goroutine reporting order, not admission order: the first waiter's goroutine calls release() -- the very thing that wakes the second waiter -- BEFORE reporting on its channel, so both sends become concurrently ready and select picks uniformly at random. On an idle machine the first goroutine almost always reaches its send before the second is scheduled, which is why it only failed on loaded CI runners. Strict FIFO is a genuine limiter invariant and it holds deterministically here: both callers are already queued when the test releases (Queued == 2 is asserted first), so the fast path is not in play, and grant order is fixed under one mutex. limiter.go is unchanged. Record admission order directly instead: each caller stamps a shared atomic.Int64 the moment Acquire returns and before it releases -- the same trick TestRaisedCapGoesToTheWaiterNotANewcomer already uses. The second waiter can only be granted from inside the first one's release, so a stamp taken before that release is a faithful record of grant order. Results are then collected from both buffered channels in a fixed order. The assertion stays strict FIFO rather than being weakened.
Deploying mcpproxy-docs with
|
| Latest commit: |
231d6c9
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://eb98d655.mcpproxy-docs.pages.dev |
| Branch Preview URL: | https://claude-silly-kowalevski-a1a7.mcpproxy-docs.pages.dev |
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
📦 Build ArtifactsWorkflow Run: View Run Available Artifacts
How to DownloadOption 1: GitHub Web UI (easiest)
Option 2: GitHub CLI gh run download 33492599381 --repo smart-mcp-proxy/mcpproxy-go
|
Both sides de-flake TestFastPathDoesNotOvertakeAQueue and agree on the diagnosis: the test was measuring goroutine reporting order rather than admission order, because the first waiter released -- the very thing that wakes the second -- before reporting, leaving both result channels ready at once for a select that picks at random. main's fix is the stronger one and is kept: startParkedCall has each admitted call PARK in the slot it wins instead of releasing, so with a cap of 1 only one of the two can be past admission at a time and the concurrent report is impossible rather than merely unlikely. It also adds occupancy assertions between the two grants. This branch's atomic sequence stamping and the awaitAdmission helper are dropped as superseded. Kept from this branch: the doc comment explaining WHY the previous version failed, so the release-before-report trap is recorded next to the helper that avoids it. Verified on the merge result: mutating grantLocked to grant from Back() (LIFO) fails the test, and dropping the waiters.Len() == 0 fast-path guard fails it too, so the merged test still catches the regression it exists for.
Member
Author
|
Closing: main landed its own fix for this flake ( |
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.
Pull Request
Description
The flake blocked at least three unrelated PRs — #1037 (telemetry-only diff) and #1153 twice in a row (a
bench/-only diff) — in both Unit Tests and End-to-End Tests onubuntu-latest.The previously recorded root cause was wrong. It was characterised as "the assertion demands strict FIFO from a fast path that only usually loses the race", i.e. a real ordering bug in
limiter.go. It is not, andlimiter.gois unchanged here.Strict FIFO is a genuine invariant the limiter promises (package doc, FR-004) and it holds deterministically in this test. By the time the test calls
held(), both callers are already parked in the queue —Queued == 2is asserted beforehand — so the fast path is not in play at all. Grant order is then fixed under one mutex:grantLockedgrants the front waiter only (Max: 1), and the second waiter can only be granted from inside the first waiter'srelease().The flake was in the test harness, which released before reporting:
release()unblocks the second goroutine, so both channel sends become concurrently ready, and aselectover two ready cases picks uniformly at random (Go spec). The test read a scheduling artifact as a FIFO violation. On an idle machine the first goroutine almost always sends before the second is even scheduled — which is why it never reproduced locally.What changed
Main's fix (
startParkedCall) is the stronger one and is kept: each admitted call parks in the slot it wins instead of releasing, so with a cap of 1 only one of the two can be past admission at a time. The concurrent report becomes impossible rather than merely unlikely, and occupancy is asserted between the two grants. This branch'satomicsequence stamping and itsawaitAdmissionhelper are dropped as superseded.What survives from this branch is the doc comment recording why the earlier version failed, so the release-before-report trap is documented next to the helper that avoids it. That is the entire remaining diff.
Testing
Verified on the merge result, so these cover main's implementation as shipped:
TestFastPathDoesNotOvertakeAQueue, 12 CPU load-generators,-count=800-race -count=5grantLockedgrants fromBack()(LIFO)waiters.Len() == 0guardgo build ./...For reference, before either fix: the pre-fix test failed under that identical 12-load-generator
-count=800stress.Notes for the reviewer
selectover two result channels can never prove ordering. When goroutine A's completion is what unblocks goroutine B, both sends land in the same instant. Worth suspecting the harness first for any Go test claiming "X happened before Y" by racing two channels.-count=Nunder load is unreliable: copy the test verbatim into a scratch file in the same package and insertfor i := 0; i < 50; i++ { runtime.Gosched() }at the suspected preemption point. That failed 20/20 instantly where-count=600under load had not reproduced at all.