Skip to content

Commit 6d6fd7f

Browse files
committed
Cancel update tasks on workflow cancellation
1 parent 4946d94 commit 6d6fd7f

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

temporalio/worker/_workflow_instance.py

+7
Original file line numberDiff line numberDiff line change
@@ -1851,6 +1851,13 @@ async def _run_top_level_workflow_function(self, coro: Awaitable[None]) -> None:
18511851
err
18521852
):
18531853
self._add_command().cancel_workflow_execution.SetInParent()
1854+
# Cancel update tasks, so that the update caller receives an
1855+
# update failed error. We do not currently cancel signal tasks
1856+
# since (a) doing so would require a workflow flag and (b) the
1857+
# presence of the update caller gives a strong reason to cancel
1858+
# update tasks.
1859+
for update_handler in self._in_progress_updates.values():
1860+
update_handler.task.cancel("The workflow was cancelled.")
18541861
elif self._is_workflow_failure_exception(err):
18551862
# All other failure errors fail the workflow
18561863
self._set_workflow_failure(err)

tests/worker/test_workflow.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -5646,7 +5646,16 @@ async def _run_workflow_and_get_warning(self) -> bool:
56465646
with pytest.WarningsRecorder() as warnings:
56475647
if self.handler_type == "-update-":
56485648
assert update_task
5649-
if self.handler_waiting == "-wait-all-handlers-finish-":
5649+
5650+
if self.workflow_termination_type == "-cancellation-":
5651+
with pytest.raises(WorkflowUpdateFailedError) as update_err:
5652+
await update_task
5653+
assert isinstance(update_err.value.cause, CancelledError)
5654+
assert (
5655+
"the workflow was cancelled"
5656+
in str(update_err.value.cause).lower()
5657+
)
5658+
elif self.handler_waiting == "-wait-all-handlers-finish-":
56505659
await update_task
56515660
else:
56525661
with pytest.raises(RPCError) as update_err:

0 commit comments

Comments
 (0)