Fix activity cancellation race when not cancelling workflow #741
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What was changed
Only decrement the in-process cancelled counter during workflow cancel.
Why?
In order to keep the event ID expectations correct, we keep a cancellation counter for things cancelled during workflow execution. This cancellation counter, which has been there for timers and reinstated in #726 for activities, is incremented upon cancel and decremented upon removal of the command. But while the increment was done only during workflow cancellation, the decrement was being done always. This makes sure that decrement is only done during workflow cancellation, when the increment occurs.
Whether we should be limiting the increment to only during workflow cancel done way back in #382, I am unsure.
The reason we saw this issue is during session cancellation which is not workflow cancellation was decrementing that counter too far. This was noticed during #739. So regression tests have been added for them.