From 15bc10d5cf99bda13f51be18f40ba033ba87a02a Mon Sep 17 00:00:00 2001 From: Yichao Yang Date: Fri, 26 May 2023 10:08:14 -0700 Subject: [PATCH] Fix mutable state get event error handling (#4396) --- common/util.go | 6 ++ .../history/workflow/mutable_state_impl.go | 66 ++++++++++++------- 2 files changed, 48 insertions(+), 24 deletions(-) diff --git a/common/util.go b/common/util.go index ea3180ee2e8..fb62b323536 100644 --- a/common/util.go +++ b/common/util.go @@ -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, ¬FoundErr) +} + // WorkflowIDToHistoryShard is used to map namespaceID-workflowID pair to a shardID. func WorkflowIDToHistoryShard( namespaceID string, diff --git a/service/history/workflow/mutable_state_impl.go b/service/history/workflow/mutable_state_impl.go index 9901f8a0d3d..f275cdcc9cf 100644 --- a/service/history/workflow/mutable_state_impl.go +++ b/service/history/workflow/mutable_state_impl.go @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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 }