Skip to content

Fix "Event loop is closed" exception in async threading on Agent Engine #2428

@vzegna

Description

@vzegna

Describe the bug
I keep getting the same "Event loop is closed" exception thrown by the agent deployed on Agent Engine, over and over again. I don't know if this is an ADK problem or Agent Engine problem, please investigate.

The log snippet below is from the Vertex AI Reasoning Engine logs in Logs Explorer:

TIMESTAMP                    SEVERITY  TEXT_PAYLOAD
2025-08-06T21:27:58.476726Z                raise self._exception
2025-08-06T21:27:58.469214Z  ERROR     Traceback (most recent call last):
                                         File "/usr/local/lib/python3.12/threading.py", line 1075, in _bootstrap_inner
                                           self.run()
                                         File "/usr/local/lib/python3.12/threading.py", line 1012, in run
                                           self._target(*self._args, **self._kwargs)
                                         File "/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.12/lib/python3.12/site-packages/google/adk/runners.py", line 158, in _asyncio_thread_main
                                           asyncio.run(_invoke_run_async())
                                         File "/usr/local/lib/python3.12/asyncio/runners.py", line 195, in run
                                           return runner.run(main)
2025-08-06T21:27:58.468101Z            Exception in thread Thread-15 (_asyncio_thread_main):
2025-08-06T21:27:00.525407Z                raise self._exception
2025-08-06T21:27:00.516718Z  ERROR     Traceback (most recent call last):
                                         File "/usr/local/lib/python3.12/threading.py", line 1075, in _bootstrap_inner
                                           self.run()
                                         File "/usr/local/lib/python3.12/threading.py", line 1012, in run
                                           self._target(*self._args, **self._kwargs)
                                         File "/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.12/lib/python3.12/site-packages/google/adk/runners.py", line 158, in _asyncio_thread_main
                                           asyncio.run(_invoke_run_async())
                                         File "/usr/local/lib/python3.12/asyncio/runners.py", line 195, in run
                                           return runner.run(main)
2025-08-06T21:27:00.514820Z            Exception in thread Thread-9 (_asyncio_thread_main):
2025-08-06T21:23:43.693912Z                raise self._exception
2025-08-06T21:23:43.681791Z  ERROR     Traceback (most recent call last):
                                         File "/usr/local/lib/python3.12/threading.py", line 1075, in _bootstrap_inner
                                           self.run()
                                         File "/usr/local/lib/python3.12/threading.py", line 1012, in run
                                           self._target(*self._args, **self._kwargs)
                                         File "/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.12/lib/python3.12/site-packages/google/adk/runners.py", line 158, in _asyncio_thread_main
                                           asyncio.run(_invoke_run_async())
                                         File "/usr/local/lib/python3.12/asyncio/runners.py", line 195, in run
                                           return runner.run(main)
2025-08-06T21:23:43.679742Z            Exception in thread Thread-57 (_asyncio_thread_main):
2025-08-06T21:22:09.385805Z  ERROR     Traceback (most recent call last):
                                         File "/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.12/lib/python3.12/site-packages/httpx/_client.py", line 1985, in aclose
                                           await self._transport.aclose()
                                         File "/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.12/lib/python3.12/site-packages/httpx/_transports/default.py", line 406, in aclose
                                           await self._pool.aclose()
                                         File "/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.12/lib/python3.12/site-packages/httpcore/_async/connection_pool.py", line 353, in aclose
                                           await self._close_connections(closing_connections)
                                         File "/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.12/lib/python3.12/site-packages/httpcore/_async/connection_pool.py", line 345, in _close_connections
                                           await connection.aclose()
                                         File "/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.12/lib/python3.12/site-packages/httpcore/_async/connection.py", line 173, in aclose
                                           await self._connection.aclose()
                                         File "/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.12/lib/python3.12/site-packages/httpcore/_async/http11.py", line 258, in aclose
                                           await self._network_stream.aclose()
                                         File "/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.12/lib/python3.12/site-packages/httpcore/_backends/anyio.py", line 53, in aclose
                                           await self._stream.aclose()
                                         File "/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.12/lib/python3.12/site-packages/anyio/streams/tls.py", line 234, in aclose
                                           await self.transport_stream.aclose()
                                         File "/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.12/lib/python3.12/site-packages/anyio/_backends/_asyncio.py", line 1314, in aclose
                                           self._transport.close()
                                         File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 1213, in close
                                           super().close()
                                         File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 875, in close
                                           self._loop.call_soon(self._call_connection_lost, None)
                                         File "/usr/local/lib/python3.12/asyncio/base_events.py", line 799, in call_soon
                                           self._check_closed()
                                         File "/usr/local/lib/python3.12/asyncio/base_events.py", line 545, in _check_closed
                                           raise RuntimeError('Event loop is closed')
                                       RuntimeError: Event loop is closed
2025-08-06T21:22:09.385756Z            future: <Task finished name='Task-20' coro=<AsyncClient.aclose() done, defined at /home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.12/lib/python3.12/site-packages/httpx/_client.py:1978> exception=RuntimeError('Event loop is closed')>
2025-08-06T21:22:09.385723Z            [8]       ERROR:    Task exception was never retrieved
2025-08-06T21:22:07.298254Z                raise self._exception
2025-08-06T21:22:07.285363Z  ERROR     Traceback (most recent call last):
                                         File "/usr/local/lib/python3.12/threading.py", line 1075, in _bootstrap_inner
                                           self.run()
                                         File "/usr/local/lib/python3.12/threading.py", line 1012, in run
                                           self._target(*self._args, **self._kwargs)
                                         File "/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.12/lib/python3.12/site-packages/google/adk/runners.py", line 158, in _asyncio_thread_main
                                           asyncio.run(_invoke_run_async())
                                         File "/usr/local/lib/python3.12/asyncio/runners.py", line 195, in run
                                           return runner.run(main)
2025-08-06T21:22:07.283174Z            Exception in thread Thread-47 (_asyncio_thread_main):
2025-08-06T20:33:42.736333Z                raise self._exception
2025-08-06T20:33:42.709730Z  ERROR     Traceback (most recent call last):
                                         File "/usr/local/lib/python3.12/threading.py", line 1075, in _bootstrap_inner
                                           self.run()
                                         File "/usr/local/lib/python3.12/threading.py", line 1012, in run
                                           self._target(*self._args, **self._kwargs)
                                         File "/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.12/lib/python3.12/site-packages/google/adk/runners.py", line 158, in _asyncio_thread_main
                                           asyncio.run(_invoke_run_async())
                                         File "/usr/local/lib/python3.12/asyncio/runners.py", line 195, in run
                                           return runner.run(main)
2025-08-06T20:33:42.707398Z            Exception in thread Thread-13 (_asyncio_thread_main):
2025-08-06T20:31:56.396374Z                raise self._exception
2025-08-06T20:31:56.383125Z  ERROR     Traceback (most recent call last):
                                         File "/usr/local/lib/python3.12/threading.py", line 1075, in _bootstrap_inner
                                           self.run()
                                         File "/usr/local/lib/python3.12/threading.py", line 1012, in run
                                           self._target(*self._args, **self._kwargs)
                                         File "/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.12/lib/python3.12/site-packages/google/adk/runners.py", line 158, in _asyncio_thread_main
                                           asyncio.run(_invoke_run_async())
                                         File "/usr/local/lib/python3.12/asyncio/runners.py", line 195, in run
                                           return runner.run(main)
2025-08-06T20:31:56.381190Z            Exception in thread Thread-6 (_asyncio_thread_main):
2025-08-06T20:31:53.549854Z                raise self._exception
2025-08-06T20:31:53.536642Z  ERROR     Traceback (most recent call last):
                                         File "/usr/local/lib/python3.12/threading.py", line 1075, in _bootstrap_inner
                                           self.run()
                                         File "/usr/local/lib/python3.12/threading.py", line 1012, in run
                                           self._target(*self._args, **self._kwargs)
                                         File "/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.12/lib/python3.12/site-packages/google/adk/runners.py", line 158, in _asyncio_thread_main
                                           asyncio.run(_invoke_run_async())
                                         File "/usr/local/lib/python3.12/asyncio/runners.py", line 195, in run
                                           return runner.run(main)
2025-08-06T20:31:53.534736Z            Exception in thread Thread-9 (_asyncio_thread_main):
2025-08-06T20:31:43.393636Z                raise self._exception

To Reproduce
Send any request to the Agent Engine instance.

Expected behavior
No exceptions should be thrown.

Screenshots
Image

Desktop (please complete the following information):

  • OS: [e.g. iOS]: MacOS Sequoia 15.6 (24G84)
  • Python 3.12.11
  • ADK version(pip show google-adk): Version: 1.10.0

Model Information:
gemini-2.5-pro

Metadata

Metadata

Assignees

Labels

agent engine[Component] This issue is related to Vertex AI Agent Engine

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions