Skip to content

Commit 6da0224

Browse files
vdusekclaude
andcommitted
fix: Isolate cleanup steps in Actor __aexit__ to prevent cascading failures
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5e4f773 commit 6da0224

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/apify/_actor.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,20 @@ 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+
for cleanup_step in [
253+
self.event_manager.__aexit__,
254+
self._charging_manager_implementation.__aexit__,
255+
]:
256+
try:
257+
await cleanup_step(None, None, None)
258+
except Exception:
259+
self.log.exception(f'Cleanup step failed: {cleanup_step}')
254260

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

258267
try:
259268
await asyncio.wait_for(finalize(), self._cleanup_timeout.total_seconds())

0 commit comments

Comments
 (0)