Skip to content

Treat TimeoutError as workflow/update failure instead of task failure #800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions temporalio/worker/_workflow_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -1712,10 +1712,11 @@ def _instantiate_workflow_object(self) -> Any:

def _is_workflow_failure_exception(self, err: BaseException) -> bool:
# An exception is a failure instead of a task fail if it's already a
# failure error or if it is an instance of any of the failure types in
# the worker or workflow-level setting
# failure error or if it is a timeout error or if it is an instance of
# any of the failure types in the worker or workflow-level setting
return (
isinstance(err, temporalio.exceptions.FailureError)
or isinstance(err, asyncio.TimeoutError)
or any(isinstance(err, typ) for typ in self._defn.failure_exception_types)
or any(
isinstance(err, typ)
Expand Down
34 changes: 34 additions & 0 deletions tests/worker/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -6923,6 +6923,40 @@ async def test_update_handler_semaphore_acquisition_respects_timeout(
)


@workflow.defn
class TimeoutErrorWorkflow:
@workflow.run
async def run(self, scenario) -> None:
if scenario == "workflow.wait_condition":
await workflow.wait_condition(lambda: False, timeout=0.01)
elif scenario == "asyncio.wait_for":
await asyncio.wait_for(asyncio.sleep(1000), timeout=0.01)
elif scenario == "asyncio.timeout":
if sys.version_info >= (3, 11):
async with asyncio.timeout(0.1):
await asyncio.sleep(1000)
else:
raise RuntimeError("Unrecognized scenario")


async def test_workflow_timeout_error(client: Client):
async with new_worker(client, TimeoutErrorWorkflow) as worker:
scenarios = ["workflow.wait_condition", "asyncio.wait_for"]
if sys.version_info >= (3, 11):
scenarios.append("asyncio.timeout")

for scenario in scenarios:
with pytest.raises(WorkflowFailureError) as err:
await client.execute_workflow(
TimeoutErrorWorkflow.run,
scenario,
id=f"workflow-{uuid.uuid4()}",
task_queue=worker.task_queue,
)
assert isinstance(err.value.cause, ApplicationError)
assert err.value.cause.type == "TimeoutError"


def check_in_workflow() -> str:
return "in workflow" if workflow.in_workflow() else "not in workflow"

Expand Down
Loading