Skip to content

Commit

Permalink
Fix mutable state get event error handling (#4396)
Browse files Browse the repository at this point in the history
  • Loading branch information
yycptt committed May 26, 2023
1 parent 6132e58 commit 15bc10d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 24 deletions.
6 changes: 6 additions & 0 deletions common/util.go
Expand Up @@ -380,6 +380,12 @@ func IsInternalError(err error) bool {
return errors.As(err, &internalErr)
}

// IsNotFoundError checks if the error is a not found error.
func IsNotFoundError(err error) bool {
var notFoundErr *serviceerror.NotFound
return errors.As(err, &notFoundErr)
}

// WorkflowIDToHistoryShard is used to map namespaceID-workflowID pair to a shardID.
func WorkflowIDToHistoryShard(
namespaceID string,
Expand Down
66 changes: 42 additions & 24 deletions service/history/workflow/mutable_state_impl.go
Expand Up @@ -785,10 +785,13 @@ func (ms *MutableStateImpl) GetActivityScheduledEvent(
currentBranchToken,
)
if err != nil {
// do not return the original error
// since original error can be of type entity not exists
// which can cause task processing side to fail silently
return nil, ErrMissingActivityScheduledEvent
if common.IsNotFoundError(err) {
// do not return the original error
// since original error of type NotFound
// can cause task processing side to fail silently
return nil, ErrMissingActivityScheduledEvent
}
return nil, err
}
return event, nil
}
Expand Down Expand Up @@ -865,10 +868,13 @@ func (ms *MutableStateImpl) GetChildExecutionInitiatedEvent(
currentBranchToken,
)
if err != nil {
// do not return the original error
// since original error can be of type entity not exists
// which can cause task processing side to fail silently
return nil, ErrMissingChildWorkflowInitiatedEvent
if common.IsNotFoundError(err) {
// do not return the original error
// since original error of type NotFound
// can cause task processing side to fail silently
return nil, ErrMissingChildWorkflowInitiatedEvent
}
return nil, err
}
return event, nil
}
Expand Down Expand Up @@ -908,10 +914,13 @@ func (ms *MutableStateImpl) GetRequesteCancelExternalInitiatedEvent(
currentBranchToken,
)
if err != nil {
// do not return the original error
// since original error can be of type entity not exists
// which can cause task processing side to fail silently
return nil, ErrMissingRequestCancelInfo
if common.IsNotFoundError(err) {
// do not return the original error
// since original error of type NotFound
// can cause task processing side to fail silently
return nil, ErrMissingRequestCancelInfo
}
return nil, err
}
return event, nil
}
Expand Down Expand Up @@ -982,10 +991,13 @@ func (ms *MutableStateImpl) GetSignalExternalInitiatedEvent(
currentBranchToken,
)
if err != nil {
// do not return the original error
// since original error can be of type entity not exists
// which can cause task processing side to fail silently
return nil, ErrMissingSignalInitiatedEvent
if common.IsNotFoundError(err) {
// do not return the original error
// since original error of type NotFound
// can cause task processing side to fail silently
return nil, ErrMissingSignalInitiatedEvent
}
return nil, err
}
return event, nil
}
Expand Down Expand Up @@ -1020,10 +1032,13 @@ func (ms *MutableStateImpl) GetCompletionEvent(
currentBranchToken,
)
if err != nil {
// do not return the original error
// since original error can be of type entity not exists
// which can cause task processing side to fail silently
return nil, ErrMissingWorkflowCompletionEvent
if common.IsNotFoundError(err) {
// do not return the original error
// since original error of type NotFound
// can cause task processing side to fail silently
return nil, ErrMissingWorkflowCompletionEvent
}
return nil, err
}
return event, nil
}
Expand Down Expand Up @@ -1070,10 +1085,13 @@ func (ms *MutableStateImpl) GetStartEvent(
currentBranchToken,
)
if err != nil {
// do not return the original error
// since original error can be of type entity not exists
// which can cause task processing side to fail silently
return nil, ErrMissingWorkflowStartEvent
if common.IsNotFoundError(err) {
// do not return the original error
// since original error of type NotFound
// can cause task processing side to fail silently
return nil, ErrMissingWorkflowStartEvent
}
return nil, err
}
return event, nil
}
Expand Down

0 comments on commit 15bc10d

Please sign in to comment.