Skip to content

Commit 43bb12e

Browse files
author
Łukasz Bobiński
committed
Fix: Improve exception handling in _cleanup_producer
1 parent 03aee6a commit 43bb12e

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/a2a/server/request_handlers/default_request_handler.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,14 @@ async def _cleanup_producer(
449449
"""Cleans up the agent execution task and queue manager entry."""
450450
try:
451451
await producer_task
452-
except (Exception, asyncio.CancelledError):
453-
# We don't want to stop cleanup if the producer task failed or was cancelled
454-
pass
452+
except asyncio.CancelledError:
453+
# The producer task was cancelled, which is an expected outcome in some scenarios.
454+
# We don't want to stop cleanup in this case.
455+
logger.debug('Producer task %s was cancelled during cleanup', task_id)
456+
except Exception:
457+
# Log other exceptions from the producer task to avoid losing error information,
458+
# but continue with the cleanup process.
459+
logger.exception('Producer task %s failed during cleanup', task_id)
455460
await self._queue_manager.close(task_id)
456461
async with self._running_agents_lock:
457462
self._running_agents.pop(task_id, None)

0 commit comments

Comments
 (0)