temporalio / sdk-core

Core Temporal SDK that can be used as a base for language specific Temporal SDKs
MIT License
271 stars 72 forks source link

[Bug] Activity cancels can wake-up workflow after it finishes #772

Open Sushisource opened 3 months ago

Sushisource commented 3 months ago

Describe the bug

Possibly other types of wake-ups could occur too. The motivating issue:

invalid command sequence: [RequestCancelActivityTask, CancelWorkflowExecution, ProtocolMessage, ProtocolMessage], command CancelWorkflowExecution must be the last command.

That sequence was caused by cancelling an activity while also cancelling the workflow. Then Core sent an activation to notify lang that the activity is now cancelled, causing it to wake up again and finish two update handlers, this all being after the workflow had already exited.

This is probably all only possible in situations where this is happening within one WFT.

More likely than not the right way to fix this is to simply not send the activation with the activity getting cancelled, since the workflow already exited there is no point.

Minimal Reproduction

Should be easy to make a UT simulating the above