Skip to content

Commit 68c2acf

Browse files
vdusekclaude
andauthored
fix: Isolate cleanup steps in Actor __aexit__ to prevent cascading failures (#842)
- Wrap each cleanup step in `finalize()` (`event_manager.__aexit__`, `_charging_manager_implementation.__aexit__`, `_save_actor_state`) with independent `try/except` blocks - Previously, if `event_manager.__aexit__()` raised, charging manager exit and state persistence were skipped entirely - Failures are now logged and don't prevent subsequent cleanup steps from executing --- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 04218d6 commit 68c2acf

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/apify/_actor.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,21 @@ async def finalize() -> None:
249249
if self._event_listeners_timeout:
250250
await self.event_manager.wait_for_all_listeners_to_complete(timeout=self._event_listeners_timeout)
251251

252-
await self.event_manager.__aexit__(None, None, None)
253-
await self._charging_manager_implementation.__aexit__(None, None, None)
252+
try:
253+
await self.event_manager.__aexit__(None, None, None)
254+
except Exception:
255+
self.log.exception('Failed to exit event manager')
256+
257+
try:
258+
await self._charging_manager_implementation.__aexit__(None, None, None)
259+
except Exception:
260+
self.log.exception('Failed to exit charging manager')
254261

255262
# Persist Actor state
256-
await self._save_actor_state()
263+
try:
264+
await self._save_actor_state()
265+
except Exception:
266+
self.log.exception('Failed to save Actor state')
257267

258268
try:
259269
await asyncio.wait_for(finalize(), self._cleanup_timeout.total_seconds())

0 commit comments

Comments
 (0)