Skip to content
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

Adds validation for workflow task for child start and cancel #599

Merged

Conversation

samarabbas
Copy link
Contributor

@samarabbas samarabbas commented Jul 23, 2020

What changed?

Adds validation to fail workflow task when child execution is started
and cancelled in the same workflow task.

Fixes #276

Why?

If client SDK starts a child workflow and then cancels it in the same workflow task Temporal
currently processes both these commands which results in the child workflow getting started
and then cancellation requested on it. This results in undesired behavior on the sdk, where much
better expectation is that child workflow is never started in the first place.

Initially we thought of implementing logic on the server to cancel the child execution immediately as
part of the workflow task processing. But after more thought it is not as simple as expected. Most
of the code around child workflows state machine is completely asynchronous and short circuiting
all that logic to synchronous cancel the child execution could be very risky.

So after discussion with @mfateev I decided to consider this as an invalid scenario and fail the entire
workflow task instead. We would add logic on the clients to never make this command if child is
started and cancelled in the same workflow task.

How did you test it?
Added new integration test TestImmediateChildCancellation_WorkflowTaskFailed

Potential risks
This state machine already results in broken experience on SDK. Does not introduces any additional risk.

Adds validation to fail workflow task when child execution is started
and cancelled in the same workflow task.
continueAsNewBuilder: nil,
stopProcessing: false,
mutableState: mutableState,
initiatedChildExecutionsInSession: make(map[string]struct{}),
Copy link
Member

Choose a reason for hiding this comment

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

Do we have a similar problem with other commands? What about activities, timers, etc?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will add integration tests for timer and activity use cases in a separate PR.

continueAsNewBuilder mutableState
stopProcessing bool // should stop processing any more commands
mutableState mutableState
initiatedChildExecutionsInSession map[string]struct{} // Set of initiated child executions in the workflow task
Copy link
Member

Choose a reason for hiding this comment

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

session is a new term. Should we call more like currentCommandBatch or something else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to initiatedChildExecutionsInBatch

@samarabbas samarabbas merged commit e0fdc8c into temporalio:master Jul 24, 2020
@samarabbas samarabbas deleted the child-cancellation-same-task-as-start branch July 24, 2020 20:00
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.

Fix handling of immediate child workflow cancellation
3 participants