Skip to content

fix(upstream): stop network errors parking no-auth servers in Pending Auth (#1537) - #1540

Merged
Dumbris merged 1 commit into
mainfrom
fix/1537-noauth-pending-auth
Oct 9, 2026
Merged

Dumbris merged 1 commit into
mainfrom
fix/1537-noauth-pending-auth

Conversation

@Dumbris

@Dumbris Dumbris commented Oct 9, 2026

Copy link
Copy Markdown
Member

Fixes #1537. A no-auth streamable-HTTP upstream could be stuck in Pending Auth / "Sign-in required" forever after a network outage. Only a daemon restart cleared it.

Root cause

  1. Go net errors quote addresses and ephemeral ports, e.g. read udp 192.168.1.20:54012->…:53: i/o timeout or dial tcp 127.0.0.1:14011. isOAuthError and isAuthError are bare substring matches that include "401" and "403". A DNS or dial failure in the no-auth strategy could therefore be read as an auth challenge, and runAuthStrategies fell through to the OAuth strategy.
  2. With no stored token, mcp-go's OAuth transport fails locally with no valid token available before it sends any request. tryOAuthAuth then returns ErrOAuthPending, and the managed client parks the server in StatePendingAuth.
  3. ShouldAutoReconnect never re-dials Pending Auth ([Bug]: Upstream reconnect has no backoff — supervisor re-dials failed servers every 30s forever, hammering dead remotes (~9k req/day) #1013). With no persisted token, the token scan never wakes the server either, so it stays parked permanently.

Fix

  • core.IsNetworkError checks the error's type:
    • Covers DNS, net.OpError, any *url.Error (no HTTP response was received), timeouts, ECONNREFUSED/ECONNRESET and EOF.
    • A typed mcp-go HTTP 401 always takes priority.
    • runAuthStrategies returns network errors directly instead of falling through to OAuth.
  • Network errors use the normal retry backoff. managed.Client.Connect sends network errors to plain SetError. Previously a 401/403 in the error text could put them on the 5 min – 24 h OAuth backoff.
  • Pending Auth is re-checked when OAuth was never confirmed:
    • The auth ladder records whether an anonymous attempt received a real HTTP 401.
    • A park with no oauth block, no stored token and no 401 sets ErrOAuthPending.Probe, which becomes ConnectionInfo.PendingAuthProbe.
    • These parks are retried every GaveUpProbeInterval (30 min).
    • Confirmed parks (real 401, oauth block, or a stored token) stay parked exactly as before.
  • Notifications: the sign-in prompt fires once per probe-park episode, not on every 30-min retry. Only Ready ends an episode, because SetError's callback runs asynchronously.

Tests

  • core:
    • TestIsNetworkError
    • Ladder tests: a DNS chain with 401 in the port and a refused dial on port 40312 must not reach OAuth.
    • A typed 401 still reaches OAuth and is recorded as a challenge.
    • An end-to-end refused dial to 127.0.0.1:1401x must not become ErrOAuthPending. This test failed before the fix.
  • managed: real-transport Connect tests:
    • Refused port: StateError, not on the OAuth backoff.
    • JSON-RPC unauthorized without a 401: probe park.
    • Real HTTP 401: permanent park.
  • types: ShouldAutoReconnect probe table and SetPendingAuthProbe.
  • notifications: one prompt across probe cycles. A stale asynchronous Error must not reset the episode.

Regression guards still pass: #464 (strategy-name substring), #1271 (an oauth block means OAuth only), and #1013 (no re-dial storm for confirmed parks).

Verification

  • go test -race passes on internal/upstream/... and internal/runtime/....
  • The CI-equivalent -tags server race subset passes.
  • scripts/test-api-e2e.sh: 70/70.
  • golangci-lint (bare and --build-tags server): no new issues compared with main.
  • Live A/B of a main build against this branch. Both ran as scratch instances against a local no-auth MCP fixture on port 14011. The server reached Ready, then the fixture was stopped and restarted:
during outage after upstream returns
main pending auth — "Sign-in required" still pending auth 5+ min later
this branch error — "Connection refused" ready, 2 tools, within 30 s

… Auth (#1537)

A DNS/dial error quotes addresses and ephemeral ports (e.g. udp :54012),
which the substring classifiers read as a "401"/"403". The auth ladder
then fell from no-auth into the OAuth strategy, where an empty token store
produced ErrOAuthPending, and Pending Auth is never auto-redialed.

- core: IsNetworkError (typed DNS/dial/timeout/EOF/*url.Error check; a
  typed HTTP 401 always wins); runAuthStrategies returns network errors
  instead of falling into OAuth
- core: the ladder records whether an anonymous attempt got a real HTTP
  401; a park without one (no oauth block, no stored token) is flagged
  ErrOAuthPending.Probe
- types: PendingAuthProbe parks are re-probed every GaveUpProbeInterval;
  confirmed parks stay parked (#1013)
- managed: network errors take the plain SetError ladder, not the 5m-24h
  OAuth backoff
- notifications: the sign-in prompt fires once per probe-park episode;
  only Ready (synchronous) ends it

Closes #1537
@cloudflare-workers-and-pages

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

📦 Build Artifacts

Workflow Run: View Run
Branch: fix/1537-noauth-pending-auth

Available Artifacts

  • archive-darwin-amd64 (31 MB)
  • archive-darwin-arm64 (28 MB)
  • archive-linux-amd64 (19 MB)
  • archive-linux-arm64 (17 MB)
  • archive-windows-amd64 (31 MB)
  • archive-windows-arm64 (27 MB)
  • frontend-dist-pr (0 MB)
  • installer-dmg-darwin-amd64 (27 MB)
  • installer-dmg-darwin-arm64 (24 MB)
  • smart-mcp-proxymcpproxy-goJGTZ92.dockerbuild (0 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 37890115527 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

@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

❌ Patch coverage is 85.71429% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/upstream/core/connection_oauth.go 20.00% 4 Missing ⚠️
internal/upstream/core/auth_evidence.go 94.87% 1 Missing and 1 partial ⚠️
internal/upstream/managed/client.go 50.00% 0 Missing and 2 partials ⚠️
internal/upstream/notifications.go 77.77% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@Dumbris
Dumbris merged commit 9366322 into main Oct 9, 2026
43 checks passed
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.

No-auth upstream stuck in 'Pending Auth' forever after network timeout (OAuth fallback on transport error)

2 participants