Skip to content

fix(oauth): prevent refresh manager deadloop on server-not-found errors [#310]#315

Merged
Dumbris merged 2 commits intomainfrom
fix/oauth-refresh-deadloop-310
Mar 1, 2026
Merged

fix(oauth): prevent refresh manager deadloop on server-not-found errors [#310]#315
Dumbris merged 2 commits intomainfrom
fix/oauth-refresh-deadloop-310

Conversation

@Dumbris
Copy link
Contributor

@Dumbris Dumbris commented Mar 1, 2026

Summary

Fixes #310 — OAuth refresh manager enters infinite loop with 0-second delays when a server is removed from config, producing 23M+ retries and flooding logs.

Root cause: Three interconnected bugs in refresh_manager.go:

  • Integer overflow in calculateBackoff: 1 << uint(retryCount) overflows int64 at retryCount >= 30, producing negative then zero durations
  • "server not found" classified as retryable: Should be terminal — the server won't reappear
  • No maximum retry limit: DefaultMaxRetries = 0 meant unlimited retries with no circuit breaker

Fixes applied:

  • Cap backoff exponent at 25; guard against non-positive results (returns MaxRetryBackoff = 5min)
  • New terminal error classification "failed_server_gone" for "server not found" and "server does not use OAuth" — stops retries immediately
  • Changed DefaultMaxRetries from 0 to 50 as circuit breaker (~2+ hours with exponential backoff)
  • Enforce MinRefreshInterval (5s) as minimum delay floor in rescheduleAfterDelay

Test plan

  • TestRefreshManager_BackoffOverflowProtection — verifies backoff is positive and capped at retryCount 30, 63, 64, 100, 1000, and 23,158,728
  • TestRefreshManager_ServerNotFoundIsTerminal — verifies immediate stop on server-not-found
  • TestRefreshManager_MaxRetryLimit — verifies circuit breaker stops retries at limit
  • TestDefaultMaxRetries_IsNonZero — guards against regression to unlimited
  • TestRefreshManager_MinimumDelayEnforced — verifies 0/negative delays clamped to 5s
  • Extended TestClassifyRefreshError with server-gone error cases
  • All 28 oauth package tests pass with -race

🤖 Generated with Claude Code

…rs [#310]

Fix three bugs causing infinite 0-delay retry loops when an OAuth
server is removed from config or becomes unavailable:

1. Integer overflow in calculateBackoff: 1<<uint(retryCount) overflows
   at retryCount>=30, producing negative then zero durations. Cap the
   exponent at 25 and guard against non-positive results.

2. "server not found" errors classified as retryable: Add new terminal
   classification "failed_server_gone" for server-not-found and
   server-does-not-use-OAuth errors that stop retries immediately.

3. No maximum retry limit: Change DefaultMaxRetries from 0 (unlimited)
   to 50 as a circuit breaker. Also enforce MinRefreshInterval (5s) as
   minimum delay floor in rescheduleAfterDelay.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Mar 1, 2026

Deploying mcpproxy-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8aebb87
Status: ✅  Deploy successful!
Preview URL: https://a68e9f56.mcpproxy-docs.pages.dev
Branch Preview URL: https://fix-oauth-refresh-deadloop-3.mcpproxy-docs.pages.dev

View logs

@github-actions
Copy link

github-actions bot commented Mar 1, 2026

📦 Build Artifacts

Workflow Run: View Run
Branch: fix/oauth-refresh-deadloop-310

Available Artifacts

  • archive-darwin-amd64 (24 MB)
  • archive-darwin-arm64 (21 MB)
  • archive-linux-amd64 (13 MB)
  • archive-linux-arm64 (11 MB)
  • archive-windows-amd64 (23 MB)
  • archive-windows-arm64 (21 MB)
  • frontend-dist-pr (0 MB)
  • installer-dmg-darwin-amd64 (26 MB)
  • installer-dmg-darwin-arm64 (24 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 22545972405 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Dumbris Dumbris merged commit fac401e into main Mar 1, 2026
23 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.

OAuth refresh goes deadloop loop

2 participants