Skip to content

Run blocking RaaS calls in worker threads so a slow login cannot stall the HTTP server - #32

Merged
saifuddinrangwala merged 1 commit into
mainfrom
fix/non-blocking-token-and-dispatch
Nov 27, 2026
Merged

saifuddinrangwala merged 1 commit into
mainfrom
fix/non-blocking-token-and-dispatch

Conversation

@saifuddinrangwala

Copy link
Copy Markdown
Collaborator

Problem

The HTTP transport stalls whenever RaaS is slow to answer. POST /token validates the credentials with a synchronous httpx.Client (_validate_raas_credentials → connect_from_mapping → api.get_versions()), and dispatcher.dispatch() does the same for every tool call (per-request RaaS login plus the RPC). Both run inside async handlers, so a slow RaaS call blocks the whole event loop: /health/live, /health/ready, /mcp and other /token requests all wait for it.

Seen in practice: a rejected login takes ~30 s on a loaded RaaS. During that time /health/live did not answer at all (5 s timeouts), and with the Helm chart's default probes (timeoutSeconds 1, failureThreshold 3) Kubernetes restarted the pod three times. Any client sending a wrong password can take the server down this way.

Affected transports: HTTP (opaque-token path and VIDB-JWT path). The stdio transport shares one client between calls and is unchanged.

Change

  • auth/token_endpoint.py: run _validate_raas_credentials with asyncio.to_thread.
  • dispatcher.py: for per-request clients (the HTTP transport) run connect_from_mapping and the RaaS RPC with asyncio.to_thread. Each per-request client is private to one call, so no state is shared between threads. The shared stdio client keeps the existing direct call.
  • CHANGELOG.md entry.

Security / auth impact

None. Credential handling, token issue/invalidation (FR-010), the approval gate and error mapping are unchanged; only where the blocking calls execute differs. Exceptions propagate from the worker thread exactly as before.

Tests

  • Added test_slow_credential_check_does_not_block_event_loop and test_http_path_does_not_block_event_loop: a ticker task shares the loop with a deliberately slow (blocking) login/RPC and the test asserts there is no gap in the loop. Both fail on main and pass with this change.
  • pytest -q: 137 passed. ruff check .: clean.

Docs

No new config keys or tools. (Follow-up worth considering separately: the chart's probe defaults are tight for a single-process server whose upstream can be slow.)

🤖 Generated with Claude Code

…l the HTTP server

The /token credential check and the dispatcher's per-request RaaS login and RPC use the
synchronous httpx.Client inside async handlers. One slow RaaS call (a rejected login took
~30 s on a loaded RaaS) blocked the whole event loop: /health/live, /mcp and other /token
requests all stalled, and with the chart's default liveness probe the pod was restarted.

Run those calls with asyncio.to_thread. Per-request clients are private to one call, so this
is safe; the stdio transport's shared client is unchanged. Tests assert that a slow login /
RPC leaves no gap in the event loop (they fail without the change).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@saifuddinrangwala
saifuddinrangwala merged commit 9b6891f into main Nov 27, 2026
10 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.

1 participant