Repository navigation
test(upstream): count only the retire fixture's own endpoint traffic - #1934
Merged
Merged
Conversation
`go test ./...` runs packages in parallel. Other packages' test clients keep reconnecting to the ports of their own closed fixtures (POST / initialize, GET / listen stream, DELETE / close, no credentials). When the OS hands such a port to the retire fixture, that traffic was counted as requests to the old endpoint: CI job 135134947938 saw 3 requests and 0 Authorization headers in TestRetire_HTTPDialParked_OldEndpointReceivesNothing/http/remove. The fixture now serves its endpoint under a path unique to it and counts a request when its path carries that token (with or without credentials) or when it carries the fixture's own credential on any path. Everything else is answered 404 and kept apart as a stray. The handler is installed before Start. The zero-request assertions are unchanged. New tests: the parked-dial scenario with stray traffic on the port (fails on the old fixture with 0 expected, 3 actual), and the fixture's controls (endpoint traffic without credentials and the fixture's credential on another path are both counted).
Review round 1 (gpt-6.1-sol): an OAuth attempt may request /.well-known/* or mcp-go's default /authorize, /token and /register without the endpoint's path or a credential. Those paths are now counted whoever sends them, so the fixture fails closed; the control test covers them.
Deploying mcpproxy-docs with
|
| Latest commit: |
e62c761
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://52283b30.mcpproxy-docs.pages.dev |
| Branch Preview URL: | https://fix-retire-fixture-endpoint.mcpproxy-docs.pages.dev |
Review round 2 (gpt-6.1-sol chunk 2 P2 x2, Opus 5.5 medium + 2 low): - the stray test and the control test mark their injected traffic with a unique query and assert it is present, not that it is the only stray, so a real reconnecting client on a reused port cannot fail them; - the controls check one request at a time with its own counter delta, including an authenticated endpoint request, /authorize and /register; - the control asserts the instance carries the credential the fixture recognises and that credentials differ per fixture; - comment reflowed; note that originOAuthPath must grow if the fixture ever advertises OAuth metadata.
Review round 3 (gpt-6.1-sol P3): the two root-path strangers shared a marker, so a fixture that dropped foreign-credential requests without recording them would still pass. Each stranger now has its own marker and all three are asserted. Comment reflowed (Opus 5.5 round 3 note).
Review round 4 (gpt-6.1-sol P2): the parked and in-section waits blocked forever if Connect failed before reaching its hook. waitHook ends the wait with the connect error, or after 20 s.
Contributor
📦 Build ArtifactsWorkflow Run: View Run Available Artifacts
How to DownloadOption 1: GitHub Web UI (easiest)
Option 2: GitHub CLI gh run download 44436595651 --repo smart-mcp-proxy/mcpproxy-go
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Dumbris
added a commit
that referenced
this pull request
Nov 19, 2026
…ient outlives its test (#1936) ## Summary Test-only. `internal/server` fixtures created `upstream.Manager`s and never shut them down. Each one kept its network-recovery watcher (#1931) running, and its clients kept reconnecting to their fixture's closed port, for the rest of the package run. Those reconnects are the stray traffic that #1918 (fresh-process allocation tests) and #1934 (retire-fixture isolation) worked around. This PR fixes the source. The numbers below come from the end of a full `go test -v -race -timeout 60m -coverprofile … -skip "E2E|Binary|MCPProtocol|TestInfoEndpoint|TestGracefulShutdownNoPanic|TestSocketInfoEndpoint" ./internal/server/` run: | | goroutines | `(*networkRecovery).run` | `startOAuthEventMonitor` | lumberjack `millRun` | |---|---|---|---|---| | main 58a824e | 3196 | **1273** | 44 | 276 | | this branch | 739 | **0** | 0 | 0 | To find the sources, I labelled each watcher goroutine with the test frame that created it (a temporary local patch, not committed). Every leaked watcher came from a direct `upstream.NewManager` in a test file. `createTestProxyWithRuntimeCfg` alone accounted for about 70% of them. None came from a runtime or server that wasn't closed. ## Changes - **`newTestUpstreamManager` / `shutdownUpstreamOnCleanup`** (`upstream_fixture_cleanup_test.go`): all 37 direct `upstream.NewManager` calls in the package now call `ShutdownAll` when the test ends. This includes the shared `createTestProxyWithRuntimeCfg`. - **`stopUpstreamBeforeFixtureClose`**: some fixtures start their upstream after the manager exists: `startCountingUpstream` and the prompt-upstream helpers in `mcp_prompt_scope_test.go` and `scope_retained_effects_test.go`. They now remove the client in a cleanup registered after the listener's close, so it runs first: the client disconnects while the stub still listens and never redials a closed port. The old `DisconnectAll` cleanups in the prompt loops ran after the fixture had already closed. - `mcp_code_execution_test.go` (package `server_test`) defers the shutdown so it runs before the storage close it depends on. - `scope_latency_test.go` inlines the shutdown, because `scope-latency.yml` copies that one file onto the merge-base checkout, where the helper doesn't exist. - **Guard**: a new `TestMain` (`leak_guard_main_test.go`) fails an otherwise passing run if any `(*networkRecovery).run` goroutine is still alive after the last test. It polls for up to 10s and prints the first 5 stacks. I checked that it catches a leak: with the helper's shutdown commented out, `-run TestAggregatedPrompt_ScopeUsesCanonicalOwner` fails with "2 upstream.Manager network-recovery watcher(s) still running". - `MCPPROXY_NETWORK_RECOVERY=off` is not set anywhere. No production code changed. The leaks were all in test fixtures. ## Found, not fixed (production shutdown gap) The 739 goroutines that remain are mostly 227 × `(*Server).forwardRuntimeStatus` and 227 × `(*Server).listenForRoutingModeRefresh`. `NewServer` starts both (`server.go:488`, `:504`), and `Server.Shutdown` stops neither: - `listenForRoutingModeRefresh` ranges over a `SubscribeEvents` channel that is never unsubscribed. - `forwardRuntimeStatus` ranges over `Runtime.statusCh`, which nothing closes. They sit idle on a channel receive and send no network traffic. They are harmless in a real process, which exits after `Shutdown`. In tests they are still 2 leaked goroutines per server. I left them for a separate production change. ## Verification - Full `internal/server` race run: `ok … 1457.449s coverage: 83.5%`, and the guard passes. - `golangci-lint run --config .github/.golangci.yml --new-from-rev=origin/main ./...`, bare and `--build-tags server`: 0 issues.
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
TestRetire_HTTPDialParked_OldEndpointReceivesNothing/http/removefailed once in the shuffled unit-test job on #1931 (job 135134947938, seed1795038088268204092) withexpected: 0, actual: 3requests and 0 Authorization headers. This PR makes the retire fixture count only its own endpoint's traffic. It is a test-only change; no production code is touched.Classification: fixture contamination, not a retirement defect
Authorization: Bearer qa-secret…, and the CI run counted 0 Authorization headers next to the 3 requests.898572804: 300/300 runs under-raceand 100/100 withGOMAXPROCS=1(6 subtests each). The full package with the CI seed passes 3/3 on macOS and 6/6 on Linux (Docker, ephemeral port range narrowed to 1,024 ports).internal/upstreamrunning, the trap caught 0 requests. Withserver,runtime,httpapiand four more packages running in parallel, asgo test ./...does on CI, it caught 535 requests in two iterations:POST /initializewith no Authorization, tagged e.g.github|TestCallTool_ProfileV3_RestDispatchPreservesTypedRefusal. 29 of the 30 tagged tests are ininternal/server; the 30th tag carried a server name but no test name.GET /listen streams andDELETE /closes with stale session ids.internal/servertests keep reconnecting to the ports of their own closed counting upstreams. When the OS reuses one of those ports for this fixture, the traffic lands here.The same class as the stray-client isolation in #1918's
dc864055d, here across processes.Fix
/fx-<random>/mcp, or/fx-<random>/ssewithWithStaticBasePath).httpServerConfignow gives each fixture a unique bearer./.well-known/*and mcp-go's default/authorize,/tokenand/register, which an OAuth attempt may reach without the token or a credential. This was review round 1, from gpt-6.1-sol.strays().Start.New tests:
TestRetire_HTTPDialParked_StrayTrafficOnThePortIsNotTheOldEndpointruns the parked-dial scenario while a stranger sendsPOST /,GET /andDELETE /to the port. With the old fixture it fails exactly like CI, for both http and sse:expected: 0, actual: 3.TestCountingUpstream_CountsItsEndpointAndItsCredentialAnywhereholds the controls. A request to the endpoint without credentials is counted. The fixture's credential on another path is counted. Origin-level OAuth paths are counted. Strangers on other paths, with or without their own credential, are not counted.Verification (macOS,
-raceunless noted)-run 'Retire|CountingUpstream' -count=20GOMAXPROCS=1 -count=10-shuffle=on -count=2.github/.golangci.yml), bare and--build-tags server, new fromorigin/mainOne earlier full-package run with the CI seed reported
FAILwhile both lint runs loaded the machine. Its output was not captured: the command kept only the last line. The later runs listed above used the final handler ordering and all passed. That failure is reported here as uncaptured, not as explained.A note on the barrier itself: disabling the retired checks in
dialgate, plus connect cancellation in the managed client, still produced no traffic in the parked scenario, because further guards stop the dial. That is unchanged by this PR. The fixture's detection is covered by the control test above.Review
gpt-6.1-sol, fixture chunk8b0057b056e7f49ad8gpt-6.1-sol, fixture / tests6e7f49ad86e7f49ad8467da1fd5467da1fd5gpt-6.1-sol, tests467da1fd5c1690a366gpt-6.1-solc1690a366e62c7610c. The first try returned no verdict and was not countedgpt-6.1-sole62c7610ce62c7610cFollow-ups, not blocking:
authcounter's "any Authorization" rule is pinned. Opus low; the request counter already catches it.Not in this PR
The
internal/servertests that leave reconnecting clients behind are the source of the stray traffic. They are a separate cleanup.Merge condition
Both reviewers are clean on
e62c7610c. Merge that exact SHA once CI is green; if the head moves, review it again. Auto-merge is not armed.