Skip to content

feat: add per-upstream concurrency limit via semaphore#25

Merged
cptrodgers merged 1 commit intomainfrom
hn/max-upstream-connections
Mar 30, 2026
Merged

feat: add per-upstream concurrency limit via semaphore#25
cptrodgers merged 1 commit intomainfrom
hn/max-upstream-connections

Conversation

@cptrodgers
Copy link
Copy Markdown
Owner

Summary

  • Adds a tokio::sync::Semaphore to AppState that caps concurrent upstream requests (default 100)
  • Permit is scoped to forward_request only — released before response streaming, so it doesn't block SSE/long responses
  • Configurable via max_concurrent_upstream in mcpr.toml

Motivation

Without a concurrency limit, slow upstream + high inbound traffic = unbounded tokio tasks holding request/response buffers → OOM. This adds natural backpressure: excess requests wait rather than accumulate.

@cptrodgers cptrodgers force-pushed the hn/max-upstream-connections branch from e8d6d8f to 80ac137 Compare March 30, 2026 02:30
@cptrodgers cptrodgers merged commit 71d84dd into main Mar 30, 2026
1 check passed
@cptrodgers cptrodgers deleted the hn/max-upstream-connections branch March 30, 2026 02:31
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.

1 participant