Skip to content

test(limiter): observe grant order, not goroutine completion order - #1154

Merged
Dumbris merged 1 commit into
mainfrom
fix/1150-flaky-limiter
Sep 1, 2026
Merged

Dumbris merged 1 commit into
mainfrom
fix/1150-flaky-limiter

Conversation

@Dumbris

@Dumbris Dumbris commented Sep 1, 2026

Copy link
Copy Markdown
Member

Fixes #1150.

The flake was in the test, not the limiter

TestFastPathDoesNotOvertakeAQueue asserted FIFO ordering by racing two buffered channel sends. Both queued callers released their slot before reporting, so the second could be granted, released, and reported while the first was still reporting. When both reports landed before the test reached its select, Go picked a ready case uniformly at random and the test failed with "FIFO violated" — in 0.00s, with the limiter having done nothing wrong.

That (0.00s) in the CI logs was the tell: the assertion resolved immediately, so nothing had timed out. It was observing the wrong thing.

The fix

Observe grant order instead of goroutine completion order — the property the test actually means to assert. No sleeps, no raised timeouts, no retries, no skip mark; those hide a flake rather than remove it, and leave the next reader unable to tell which happened.

Verification

  • 200 runs (-count=200): pass
  • 100 runs with -race: pass

Prior evidence it was flaky on main, not PR-specific: run 33374513826 (commit 1041e4ec, main) and run 33418347015 (a PR not touching the package) both failed identically.

Reviewed under three adversarial lenses (correctness / security / regression): clean, no findings.

…1150)

TestFastPathDoesNotOvertakeAQueue asserted FIFO by racing two buffered
channel sends. Both queued callers released their slot BEFORE reporting,
so the second could be granted, released and reported while the first
was still reporting. When both reports landed before the test reached
its select, Go picked a ready case uniformly at random and the test
failed with "FIFO violated" in 0.00s — the limiter having done nothing
wrong.

Reproduced on the unfixed tree (macOS arm64, GOMAXPROCS=4, -count=500),
and pinned to the select: inserting a 20ms pause after held() so both
reports are buffered first fails 21/40 runs, i.e. the coin flip.

Each queued call now parks in the slot it wins until the test hands it
back. Under a cap of 1 that makes at most one call reachable past
admission at a time, so the two admissions can never be reported
concurrently and the order read is the order granted. The test also
pins Running/Queued while the first caller holds the slot, and after
both drain.

No production behaviour changes. The rewritten test still catches the
regressions it was written for: dropping the fast path's queue guard
and serving the queue tail instead of its head both fail it 5/5.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying mcpproxy-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: a2e74f5
Status: ✅  Deploy successful!
Preview URL: https://8ce25baa.mcpproxy-docs.pages.dev
Branch Preview URL: https://fix-1150-flaky-limiter.mcpproxy-docs.pages.dev

View logs

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

📦 Build Artifacts

Workflow Run: View Run
Branch: fix/1150-flaky-limiter

Available Artifacts

  • archive-darwin-amd64 (29 MB)
  • archive-darwin-arm64 (26 MB)
  • archive-linux-amd64 (17 MB)
  • archive-linux-arm64 (15 MB)
  • archive-windows-amd64 (29 MB)
  • archive-windows-arm64 (26 MB)
  • frontend-dist-pr (0 MB)
  • installer-dmg-darwin-amd64 (23 MB)
  • installer-dmg-darwin-arm64 (21 MB)

How to Download

Option 1: GitHub Web UI (easiest)

  1. Go to the workflow run page linked above
  2. Scroll to the bottom "Artifacts" section
  3. Click on the artifact you want to download

Option 2: GitHub CLI

gh run download 33468753754 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

@Dumbris
Dumbris merged commit e016b23 into main Sep 1, 2026
37 checks passed
@Dumbris
Dumbris deleted the fix/1150-flaky-limiter branch September 1, 2026 06:49
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.

Flaky: TestFastPathDoesNotOvertakeAQueue fails intermittently on ubuntu in Unit Tests

2 participants