fix: close the platform events websocket iterator on shutdown - #1077
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1077 +/- ##
==========================================
- Coverage 91.92% 91.90% -0.03%
==========================================
Files 51 51
Lines 3232 3235 +3
==========================================
+ Hits 2971 2973 +2
- Misses 261 262 +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
August 4, 2026 11:51
B4nan
approved these changes
Aug 4, 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.
Since v4.0.0, an Actor logs
RuntimeError: aclose(): asynchronous generator is already runningright afterActor.exit(). Cosmetic - the exit code stays 0 and no data is lost - but it shows up in every run and looks like a failure.ApifyEventManager._process_platform_messagesiterateswebsocketsconnect(...)withasync for. That iterator is an async generator, and neitherbreaknor cancelling the task closes it, so the garbage collector does - duringasyncio.runteardown, where theaclose()it schedules lands after_cancel_all_taskstook its task snapshot and is never awaited.loop.shutdown_asyncgens()then callsaclose()on a generator that is still running. Up to v3.4.1 the code usedasync with connect(...), which unwound synchronously on cancellation.contextlib.aclosingcloses the iterator on every exit path -break, exception and cancellation alike. The rest of the diff is the loop body re-indenting, a unit test that asserts the iterator is closed, and an E2E test that asserts the error is absent from a run log.Reported on Discord.
✍️ Drafted by Claude Code