Skip to content

test: bound serve_in_thread teardown to prevent CI hangs#1892

Merged
vdusek merged 1 commit into
masterfrom
fix/test-server-thread-join-hang
May 12, 2026
Merged

test: bound serve_in_thread teardown to prevent CI hangs#1892
vdusek merged 1 commit into
masterfrom
fix/test-server-thread-join-hang

Conversation

@vdusek
Copy link
Copy Markdown
Collaborator

@vdusek vdusek commented May 12, 2026

The session-scoped http_server fixture's teardown in tests/unit/server.py called thread.join() with no timeout. When uvicorn occasionally fails to honor should_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:

  1. thread.join(timeout=10) — wait for graceful shutdown.
  2. If still alive, set server.force_exit = True and thread.join(timeout=5) — uvicorn's documented hard-exit path.
  3. Mark the worker thread as daemon=True so an abandoned thread cannot keep the interpreter alive at process exit.

Observed failure: https://github.com/apify/crawlee-python/actions/runs/25720617454/job/75520659980

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.
@vdusek vdusek added t-tooling Issues with this label are in the ownership of the tooling team. adhoc Ad-hoc unplanned task added during the sprint. labels May 12, 2026
@vdusek vdusek self-assigned this May 12, 2026
@github-actions github-actions Bot added this to the 140th sprint - Tooling team milestone May 12, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.84%. Comparing base (0e7402f) to head (e1fec6b).

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     
Flag Coverage Δ
unit 92.84% <ø> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vdusek vdusek requested a review from janbuchar May 12, 2026 08:33
@vdusek vdusek merged commit 0c89b6e into master May 12, 2026
32 checks passed
@vdusek vdusek deleted the fix/test-server-thread-join-hang branch May 12, 2026 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants