Skip to content

Conversation

@vdusek
Copy link
Contributor

@vdusek vdusek commented Feb 11, 2026

Summary

  • When Actor cleanup exceeded _cleanup_timeout, the unhandled TimeoutError from asyncio.wait_for left the Actor in a broken state
  • _is_initialized was never reset to False, event/charging managers could be left partially shut down, and sys.exit() was never called even when _exit_process was True
  • Now the TimeoutError is caught, critical resource cleanup (event manager, charging manager) is forced even after timeout, and _is_initialized is always reset via a finally block

Test plan

  • Verify existing tests pass
  • Test Actor exit with a very short _cleanup_timeout and a slow event listener to confirm the timeout path logs a warning and still completes shutdown cleanly

🤖 Generated with Claude Code

When Actor cleanup exceeded `_cleanup_timeout`, the unhandled
`TimeoutError` from `asyncio.wait_for` left the Actor in a broken
state: `_is_initialized` was never reset, event/charging managers
were left partially shut down, and `sys.exit()` was never called.

Now the timeout is caught and critical resource cleanup (event manager,
charging manager) is attempted even after timeout. `_is_initialized`
is reset in a `finally` block to guarantee consistent state.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vdusek vdusek added adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. labels Feb 11, 2026
@vdusek vdusek self-assigned this Feb 11, 2026
@github-actions github-actions bot added this to the 134th sprint - Tooling team milestone Feb 11, 2026
@codecov
Copy link

codecov bot commented Feb 11, 2026

Codecov Report

❌ Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.86%. Comparing base (56aa42e) to head (ce4dfcf).
⚠️ Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
src/apify/_actor.py 60.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #776      +/-   ##
==========================================
- Coverage   81.91%   81.86%   -0.06%     
==========================================
  Files          46       46              
  Lines        2693     2696       +3     
==========================================
+ Hits         2206     2207       +1     
- Misses        487      489       +2     
Flag Coverage Δ
integration 55.93% <60.00%> (-0.03%) ⬇️
unit 68.02% <60.00%> (-0.04%) ⬇️

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.

Removed the forced __aexit__ calls on event_manager and charging_manager
after timeout - if finalize() timed out, those calls would likely hang too.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vdusek vdusek requested a review from janbuchar February 11, 2026 09:45
@vdusek vdusek merged commit fb13765 into master Feb 11, 2026
28 of 29 checks passed
@vdusek vdusek deleted the fix/actor-aexit-timeout-handling branch February 11, 2026 10:10
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.

2 participants