Repository navigation
Run blocking RaaS calls in worker threads so a slow login cannot stall the HTTP server - #32
Merged
Conversation
…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>
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.
Problem
The HTTP transport stalls whenever RaaS is slow to answer.
POST /tokenvalidates the credentials with a synchronoushttpx.Client(_validate_raas_credentials→connect_from_mapping→api.get_versions()), anddispatcher.dispatch()does the same for every tool call (per-request RaaS login plus the RPC). Both run insideasynchandlers, so a slow RaaS call blocks the whole event loop:/health/live,/health/ready,/mcpand other/tokenrequests all wait for it.Seen in practice: a rejected login takes ~30 s on a loaded RaaS. During that time
/health/livedid not answer at all (5 s timeouts), and with the Helm chart's default probes (timeoutSeconds1,failureThreshold3) 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_credentialswithasyncio.to_thread.dispatcher.py: for per-request clients (the HTTP transport) runconnect_from_mappingand the RaaS RPC withasyncio.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.mdentry.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
test_slow_credential_check_does_not_block_event_loopandtest_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 onmainand 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