Skip to content

Production error - Task was destroyed but it is pending AND cannot reuse already awaited coroutine

Problem

We are getting production error:

{"correlation_id":"undefined", "event":"Task exception was never retrieved
future: <Task finished name='Task-13066' coro=<AsyncExitStack.__aexit__() done, defined at /usr/local/lib/python3.11/contextlib.py:698> exception=RuntimeError('cannot reuse already awaited coroutine')>", "exception":"Traceback (most recent call last):
  File "/usr/local/lib/python3.11/contextlib.py", line 745, in __aexit__
    raise exc_details[1]
  File "/usr/local/lib/python3.11/contextlib.py", line 728, in __aexit__
    cb_suppress = await cb(*exc_details)
                  ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/duo-workflow-service-9TtSrW0h-py3.11/lib/python3.11/site-packages/langgraph/pregel/executor.py", line 191, in __aexit__
    raise exc
RuntimeError: cannot reuse already awaited coroutine", "gitlab_global_user_id":"undefined", "level":"error", "logger":"asyncio", "timestamp":"2025-04-29T20:00:09.750836Z", "workflow_id":"undefined"}

this log was followed by:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/contextlib.py", line 745, in __aexit__
    raise exc_details[1]
  File "/usr/local/lib/python3.11/contextlib.py", line 728, in __aexit__
    cb_suppress = await cb(*exc_details)
                  ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/duo-workflow-service-9TtSrW0h-py3.11/lib/python3.11/site-packages/langgraph/pregel/executor.py", line 191, in __aexit__
    raise exc
RuntimeError: cannot reuse already awaited coroutine

Sentry log

log record

workflow_id: "undefined"

Note: This happened only once in the last 14 days.

Edited by Halil Coban