Repository navigation
Fix flaky unit test from aiosqlite failed-connect thread race - #250
Merged
Merged
Conversation
A failed aiosqlite connect queues its worker-thread shutdown without waiting for it (omnilib/aiosqlite#394). When the test's event loop closed first, the thread raised "Event loop is closed", and pytest reported it as an unhandled thread exception in the next test. This flaked test (3.13) on main after #249. Join the worker threads in the unreachable_settings fixture teardown, off the event loop, so the loop is still alive when the thread finishes.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
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.



Summary
test (3.13)failed onmainafter #249 withPytestUnhandledThreadExceptionWarning: Exception in thread Thread-1 (_connection_worker_thread)/RuntimeError: Event loop is closed, reported againsttest_probes_over_http_when_the_database_is_down.Cause
This is upstream bug omnilib/aiosqlite#394, which is still open in 0.22.1, the latest release.
Connection.stop(), which queues the worker-thread shutdown with a future on the current loop and never awaits it.test_readiness_fails_when_the_database_is_unreachableconnects to an impossible SQLite path.call_soon_threadsaferaises. pytest then attributes the exception to whichever test runs next.It is a timing race. It did not reproduce locally with CI's seed (
3245780680), and it has not appeared in earlier CI runs. #249 does not touch the database layer.Fix
The
unreachable_settingsfixture is now async. In teardown it joins any aiosqlite worker threads viaanyio.to_thread.run_sync, so the event loop stays alive and keeps handling the thread's final callback until the thread exits.Verification
make checkpasses.Opened by claude-opus-5-5