Repository navigation
Auth middleware: database failures are a 503 with a body, not an empty 500; fix the flaky parallel-install test - #117
Merged
Merged
Conversation
…t an empty 500 The parallel-install integration test failed now and then with an empty 500. The cause was not the install transaction: the test harness ground each login's proof of work inline on the current-thread runtime that also drives the in-process server. A slow grind froze an install already in flight, its connection-pool acquire outlived the 5 s acquire timeout (with idle connections in the pool), and the session check in require_auth mapped the error to a bare 500 without logging it. - auth_guard / api_key_auth: database errors in the session and API-key checks go through the same mapping as handlers (pool timeout -> 503 with a JSON body, other errors -> 500 with one) and are logged with the lookup that failed. - test-support: grind the proof of work on the blocking pool so the server keeps running while a client logs in. - mcp_store_concurrency: log every session in before firing the installs, so they actually race each other. Co-Authored-By: Claude Opus 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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
mcp_store_concurrency::parallel_installs_same_template_keep_count_in_syncfailed intermittently on dev with500 Internal Server Errorand an empty body.Root cause
Not the install transaction (advisory lock,
FOR UPDATEon the template row andinstall_count = install_count + 1are all correct, and Postgres logged no error at the time of either failure). The 500 came from the console auth middleware:#[tokio::test]current-thread runtime that also drives the in-process server.acquire_timeout, even though the pool held idle connections. With temporary logging, every reproduced failure showedpool timed out while waiting for an open connectionwithpool_size=4..5, pool_idle=2..3out of 20.require_authmapped that error to a bareStatusCode::INTERNAL_SERVER_ERROR. The permission lookup did this without any log line, which is why CI showed onlyrequest failed ... 500 latency_ms=5004.Changes
auth_guard.rs,api_key_auth.rs): database errors in the session check, the console API-key path and the gateway API-key path now use the sameFrom<sqlx::Error> for AppErrormapping as handlers. A pool timeout is a 503 with the standard JSON error body; any other database error is a 500 with one. Each is logged with the name of the lookup that failed. Unit tests cover both mappings.test-support/src/client.rs): the proof of work is ground onspawn_blocking, so the server keeps serving while a test client logs in. This affects every test that logs in while requests are in flight.mcp_store_concurrency.rs): all sessions log in before any install fires, so the five installs actually race each other instead of trickling out one login apart.[Unreleased]Fixed entry.Reproduction (local, Postgres 18 + Redis 8 in dedicated containers, CPU saturated with busy loops to mimic a loaded runner)
require_auth, one 503 from the handler's own pool acquire)With the machine idle, both before and after pass 10/10. Locally: clippy
-D warnings(lib/bins and tests), fmt andnextest --lib --bins(840 passed) all pass. The integration suite run without ClickHouse gave 386 passed; all 72 failures were ClickHouse-database creation.🤖 Generated with Claude Code