You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: ActiveTask.start() leaves the event queue dispatchers pending when setup fails #1421
ActiveTask (src/a2a/server/agent_execution/active_task.py) creates its two EventQueueSource queues in __init__, and each EventQueueSource starts its dispatcher task as soon as it is created (src/a2a/server/events/event_queue_v2.py):
When the setup in start() fails, the except block marks the task as finished and re-raises, but never closes the queues:
exceptException:
logger.debug('ActiveTask[%s]: Setup failed, cleaning up', self._task_id)
self._is_finished.set()
ifself._reference_count==0andself._on_cleanup:
self._on_cleanup(self)
raise# _event_queue_agent and _event_queue_subscribers stay open
The setup fails when the stored task is in a terminal state (UnsupportedOperationError) or is missing and create_task_if_missing is false (TaskNotFoundError). With DefaultRequestHandler, a SendMessage to a completed task takes the first path, so each rejected request leaves two _dispatch_loop tasks pending. Once they are garbage collected, asyncio logs:
Task was destroyed but it is pending!
task: <Task pending name='Task-28' coro=<EventQueueSource._dispatch_loop() ...>>
On a server built with DefaultRequestHandler, InMemoryTaskStore and the JSON-RPC and REST routes, six SendMessage requests to completed tasks log this twelve times.
Suggested fix: close both queues in the except block, before _on_cleanup:
Hi @cchinchilla-dev , thanks for reporting this and diagnosing. I was able to reproduce this issue.
You identified the exact root cause regarding the unclosed EventQueueSource dispatcher tasks when ActiveTask.start()encounters a setup failure.
Thanks for contributing towards the fix. Your fix in PR #1422 cleanly closes both queues before cleanup and completely resolves the task leak. Assigning this issue to you till your PR gets reviewed.
Activity
rohityan commentedon Nov 4, 2026
Hi @cchinchilla-dev , thanks for reporting this and diagnosing. I was able to reproduce this issue.
You identified the exact root cause regarding the unclosed
EventQueueSourcedispatcher tasks whenActiveTask.start()encounters a setup failure.Thanks for contributing towards the fix. Your fix in PR #1422 cleanly closes both queues before cleanup and completely resolves the task leak. Assigning this issue to you till your PR gets reviewed.