fix: prevent deadlock when Actor.exit() is called from an event listener#1061
Open
vdusek wants to merge 3 commits into
Open
fix: prevent deadlock when Actor.exit() is called from an event listener#1061vdusek wants to merge 3 commits into
vdusek wants to merge 3 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1061 +/- ##
==========================================
+ Coverage 91.89% 91.95% +0.06%
==========================================
Files 51 51
Lines 3232 3245 +13
==========================================
+ Hits 2970 2984 +14
+ Misses 262 261 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
vdusek
marked this pull request as ready for review
July 21, 2026 11:06
Pijukatel
reviewed
Jul 21, 2026
Contributor
Author
|
maybe we can close this in favor of apify/crawlee-python#2088 |
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.
Actor.exit()/Actor.fail()called from within an event listener (e.g. anABORTINGhandler cleaning up on a graceful abort) deadlocked into aRecursionErrorand never completed cleanup. The cleanup path waits for all tracked event-listener tasks to finish - including the listener task that calledexit()- so it awaits its own await-chain; when that wait times out the cancellation recurses into itself. As a resultActor._activestayedTrue, the event and charging managers never shut down, state was never persisted, andsys.exitnever ran - the run only died when force-killed.The fix detaches the caller's own task from the event manager's listener-task set for the duration of cleanup and restores it afterwards (so its wrapper can still deregister it), so neither the direct wait nor the one inside the event-manager shutdown blocks on it. It's a no-op on the normal, non-listener exit path, and mirrors the workaround
reboot()already uses for this same deadlock class.The regression test registers an
ABORTINGlistener that callsActor.exit()and asserts the exit completes, the event manager shuts down, and noRecursionErroris logged; it fails on the old code and passes with the fix.✍️ Drafted by Claude Code