Fix cancelling a local activity during its retry backoff (#1972) · temporalio/sdk-python@c1b63bf · GitHub
Skip to content

Commit c1b63bf

Browse files
authored
Fix cancelling a local activity during its retry backoff (#1972)
1 parent 482e933 commit c1b63bf

3 files changed

Lines changed: 70 additions & 5 deletions

File tree

‎changelog/fixed/snoozing-sloth.md‎

Lines changed: 1 addition & 0 deletions

‎temporalio/worker/_workflow_instance.py‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,10 +2087,8 @@ def _outbound_schedule_activity(
20872087

20882088
# Function that runs in the handle
20892089
async def run_activity() -> Any:
2090+
handle._started = True
20902091
while True:
2091-
# Mark it as started each loop because backoff could cause it to
2092-
# be marked as unstarted
2093-
handle._started = True
20942092
try:
20952093
return await self._await_temporal_operation(
20962094
handle._result_fut,
@@ -3455,8 +3453,8 @@ def _resolve_backoff(
34553453
self._result_fut.set_exception(_ActivityDoBackoffError(backoff))
34563454
# Replace the result future since that one is resolved now
34573455
self._result_fut = self._instance.create_future()
3458-
# Mark this as not started since it's a new future
3459-
self._started = False
3456+
# Leave _started set: run_activity is running and traps a cancel in its
3457+
# backoff sleep, and Core has no command for the new seq to cancel yet
34603458

34613459
def _apply_schedule_command(
34623460
self,

‎tests/worker/test_workflow.py‎

Lines changed: 66 additions & 0 deletions

0 commit comments

Comments
 (0)