Repository navigation
Test: Fix two flaky test failures (refresh_lock waiter, sse-starlette shutdown flag leak) - #709
Merged
Merged
Conversation
test_waiter_observes_result_without_acquiring_second_lease inherited the module's 0.1s REFRESH_LOCK_WAIT_SECONDS patch, but its holder-to-waiter handoff spans several asyncio.to_thread hops. On a loaded CI runner that exceeded 100ms and raised OAuthCoordinationError (CI run 45930997158). The test doesn't exercise the timeout, so give it a 5s budget.
test_mcp_downstream_pool runs a real uvicorn.Server in-process, which binds SIGTERM to server.handle_exit while serving. sse-starlette's shutdown watcher finds the server through that handler; when the test sets should_exit at teardown and the watcher's 0.5s poll lands before the loop closes, it sets the process-global AppStatus.should_exit, which is never reset. Every later EventSourceResponse then closes with no events, failing 22 SSE tests in test_mcpgw_stateless, test_mcp_downstream and test_protocol_gate (CI run 46056676626). - Serve the pool test through a uvicorn.Server subclass whose capture_signals is a no-op, so the watcher can't reach the server. - Add an autouse conftest fixture that resets AppStatus.should_exit after each test, as a guard against future leaks.
refresh_lock waiter handoff testrefresh_lock waiter, sse-starlette shutdown flag leak)
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.
Fixes two unrelated CI flakes. Both depend on runner timing and neither is caused by a code change.
1.
test_waiter_observes_result_without_acquiring_second_lease(registry-pkgs)It failed on
mainin run 45930997158 and earlier in 44538549010, withOAuthCoordinationError: Token refresh already in progress; retry. The test used the file-wide 0.1sREFRESH_LOCK_WAIT_SECONDS, but its holder-to-waiter handoff goes through severalasyncio.to_threadcalls. On a busy runner with coverage on, those took longer than 100ms. The test doesn't check the timeout, so it now sets a 5s budget. The other tests still use 0.1s, including the one that checks the timeout.2. 22 SSE test failures in
registryThese failed in run 46056676626, in
test_mcpgw_stateless,test_mcp_downstreamandtest_protocol_gate. The errors wereinitialize SSE body was truncatedandChild exited without calling task_status.started().Cause:
test_mcp_downstream_pool.pyruns a realuvicorn.Serverin-process. While it serves, uvicorn sets the process's SIGTERM handler toserver.handle_exit.sse-starlette's shutdown watcher finds the server through that handler. When the test setsshould_exitat teardown and the watcher's 0.5s check runs before the loop closes, it sets the process-globalAppStatus.should_exit = True, and nothing resets it. Every laterEventSourceResponsein the session then closes with no events. I reproduced CI's exact 22-failure set locally by making the watcher check faster.Changes:
_NoSignalServer, auvicorn.Serversubclass whosecapture_signalsdoes nothing, so the watcher can't find the server.registry/tests/conftest.pyresetsAppStatus.should_exitafter each test, in case another test leaks it later.After the fix the reproduction passes (169 passed), and the full
registrysuite passes (3633 passed).