fix: exit already-entered contexts when Actor or event manager init fails#969
Open
vdusek wants to merge 1 commit into
Open
fix: exit already-entered contexts when Actor or event manager init fails#969vdusek wants to merge 1 commit into
vdusek wants to merge 1 commit into
Conversation
…ails A failed `__aenter__` never triggers `__aexit__`, so when the charging manager or the platform events websocket failed to initialize, the already-entered event manager was left active with its recurring persist-state task dangling.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #969 +/- ##
==========================================
- Coverage 89.91% 89.87% -0.05%
==========================================
Files 49 49
Lines 3085 3090 +5
==========================================
+ Hits 2774 2777 +3
- Misses 311 313 +2
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:
|
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.
Description
A failed
__aenter__never triggers__aexit__, so resources entered earlier inside__aenter__must be unwound manually before re-raising. Two paths leaked this way:ApifyEventManager.__aenter__raised on a websocket connection failure without exiting the already-entered parentEventManager, leaving its recurring persist-state task dangling._ActorType.__aenter__left the event manager entered when the charging manager's__aenter__raised.Both paths now exit the already-entered context before propagating the exception.
except BaseExceptionis used deliberately so that aCancelledErrorduring charging manager init also unwinds the event manager.Testing
test_failed_charging_manager_init_does_not_leak_event_manager).test_lifecycle_on_platform_without_websocketwith assertions that the event manager is inactive and the persist-state task is stopped after the failure.