Skip to content

Properly handle uncaught child/activity cancel during workflow cancel #71

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 3 commits into from
Jul 14, 2022

Conversation

cretz
Copy link
Member

@cretz cretz commented Jul 13, 2022

What was changed

When a workflow cancel has ever been requested (even if it was a long time ago), we unwrap any activity or child workflow cancel error to be treated as a workflow error.

Why?

When not doing this, the workflow will be considered "failed" with an activity or child error even on uncaught cancel. The downside is that the workflow will be considered cancelled if, say, you disregarded a cancel a long time ago but then way later chose to manually cancel an activity and bubbled that error out. There is no good way to handle this rare situation.

Checklist

  1. Closes Properly treat activity/child cancellation errors bubbled as workflow cancel #70

@cretz cretz requested a review from a team July 13, 2022 12:30
@cretz cretz marked this pull request as ready for review July 13, 2022 12:30
Comment on lines +1130 to +1137
if (
self._cancel_requested
and (
isinstance(err, temporalio.exceptions.ActivityError)
or isinstance(err, temporalio.exceptions.ChildWorkflowError)
)
and isinstance(err.cause, temporalio.exceptions.CancelledError)
):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might make sense to just pull the part inside the first and clause out into a var to make it a bit easier to read

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the auto-formatter we are forced to use makes this look ugly. It gets worse with a var:

            activity_or_child = isinstance(
                err, temporalio.exceptions.ActivityError
            ) or isinstance(err, temporalio.exceptions.ChildWorkflowError)
            if (
                self._cancel_requested
                and activity_or_child
                and isinstance(err.cause, temporalio.exceptions.CancelledError)
            ):
                err = err.cause

The Python SDK looks much uglier because of this formatter, but it's the industry norm. It's also why few-hundred line files look like thousands.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to not loving black but it is the standard now so 🤷

…lation

# Conflicts:
#	temporalio/worker/workflow_instance.py
@cretz cretz merged commit e5bd9a9 into temporalio:main Jul 14, 2022
@cretz cretz deleted the bubble-cancellation branch July 14, 2022 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Properly treat activity/child cancellation errors bubbled as workflow cancel
3 participants