Skip to content

Commit

Permalink
Disallow marking activity as cancelled without activity being request…
Browse files Browse the repository at this point in the history
… cancelled first (#2344)

* Disallow marking activity as cancelled without activity being request cancelled first
  • Loading branch information
wxing1292 authored Jan 6, 2022
1 parent 412035f commit ec65088
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions service/history/consts/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ var (
ErrStaleState = errors.New("cache mutable state could potentially be stale")
// ErrActivityTaskNotFound is the error to indicate activity task could be duplicate and activity already completed
ErrActivityTaskNotFound = serviceerror.NewNotFound("invalid activityID or activity already timed out or invoking workflow is completed")
// ErrActivityTaskNotCancelRequested is the error to indicate activity to be canceled is not cancel requested
ErrActivityTaskNotCancelRequested = serviceerror.NewInvalidArgument("unable to mark activity as canceled without activity being request canceled first")
// ErrWorkflowCompleted is the error to indicate workflow execution already completed
ErrWorkflowCompleted = serviceerror.NewNotFound("workflow execution already completed")
// ErrWorkflowExecutionNotFound is the error to indicate workflow execution does not exist
Expand Down
5 changes: 5 additions & 0 deletions service/history/historyEngine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1642,6 +1642,11 @@ func (e *historyEngineImpl) RespondActivityTaskCanceled(
return nil, consts.ErrActivityTaskNotFound
}

// sanity check if activity is requested to be cancelled
if !ai.CancelRequested {
return nil, consts.ErrActivityTaskNotCancelRequested
}

if _, err := mutableState.AddActivityTaskCanceledEvent(
scheduleID,
ai.StartedId,
Expand Down

0 comments on commit ec65088

Please sign in to comment.