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
The workflow below succeeds, but an exception occurs and is logged by the worker. In the example below this exception does not cause a workflow or workflow task failure, but we should nevertheless prevent it. What happens is:
An asyncio.Task is created, which blocks on a timer.
The task is cancelled, which throws asyncio.CancelledError into the coroutine, and cancels the sleep future.
But SDK internals have set a callback that attempts to resolve the future. This callback still fires at the set timer time, despite the future having been cancelled in the interim, causing asyncio.exceptions.InvalidStateError. See
🔴 caught asyncio.CancelledError when sleeping in task
Exception in callback _WorkflowInstanceImpl.workflow_sleep.<locals>.<lambda>() at /Users/dan/src/temporalio/sdk-python/temporalio/worker/_workflow_instance.py:1456
handle: <_TimerHandle when=1741139892.760706 _WorkflowInstanceImpl.workflow_sleep.<locals>.<lambda>() at /Users/dan/src/temporalio/sdk-python/temporalio/worker/_workflow_instance.py:1456>
Traceback (most recent call last):
File "/Users/dan/.local/share/uv/python/cpython-3.13.1-macos-aarch64-none/lib/python3.13/asyncio/events.py", line 89, in _run
self._context.run(self._callback, *self._args)
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dan/src/temporalio/sdk-python/temporalio/worker/_workflow_instance.py", line 1456, in <lambda>
lambda: fut.set_result(None),
~~~~~~~~~~~~~~^^^^^^
asyncio.exceptions.InvalidStateError: invalid state
Result: Hello, World!
👍 Should just not call set_result on an already done future (and find where else we might be doing that). This is probably just us (me) not properly thinking about the fact that in Python's asyncio.Future set-result-if-already-done is not a no-op (as it is in other langs and as concurrent.futures.Future result setter was until 3.8).
The workflow below succeeds, but an exception occurs and is logged by the worker. In the example below this exception does not cause a workflow or workflow task failure, but we should nevertheless prevent it. What happens is:
asyncio.Task
is created, which blocks on a timer.asyncio.CancelledError
into the coroutine, and cancels thesleep
future.asyncio.exceptions.InvalidStateError
. Seesdk-python/temporalio/worker/_workflow_instance.py
Lines 1453 to 1457 in 49ca10e
The text was updated successfully, but these errors were encountered: