test: bound serve_in_thread teardown to prevent CI hangs#1892
Merged
Conversation
The session-scoped `http_server` fixture's teardown called `thread.join()` without a timeout. When uvicorn occasionally ignored `should_exit`, the join blocked until pytest-timeout killed the run after 30 minutes. Bound the join, escalate to `force_exit`, and mark the worker thread as a daemon.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1892 +/- ##
==========================================
+ Coverage 92.82% 92.84% +0.01%
==========================================
Files 167 167
Lines 11699 11699
==========================================
+ Hits 10860 10862 +2
+ Misses 839 837 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
janbuchar
approved these changes
May 12, 2026
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.
The session-scoped
http_serverfixture's teardown intests/unit/server.pycalledthread.join()with no timeout. When uvicorn occasionally fails to honorshould_exit(it's stuck inside the asyncio loop's selector poll), the join blocks indefinitely — pytest-timeout eventually kills the run after 30 minutes, taking down the whole job.The fix bounds the teardown:
thread.join(timeout=10)— wait for graceful shutdown.server.force_exit = Trueandthread.join(timeout=5)— uvicorn's documented hard-exit path.daemon=Trueso an abandoned thread cannot keep the interpreter alive at process exit.Observed failure: https://github.com/apify/crawlee-python/actions/runs/25720617454/job/75520659980