Skip to content

Commit 67ee9b9

Browse files
authored
Improve check for invalid pollForDecisionTaskResponse (#1122)
1 parent 999748d commit 67ee9b9

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

internal/internal_task_pollers.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -808,14 +808,22 @@ func (wtp *workflowTaskPoller) poll(ctx context.Context) (interface{}, error) {
808808
func (wtp *workflowTaskPoller) toWorkflowTask(response *s.PollForDecisionTaskResponse) *workflowTask {
809809
startEventID := response.GetStartedEventId()
810810
nextEventID := response.GetNextEventId()
811-
if nextEventID != 0 &&
812-
startEventID != 0 &&
813-
nextEventID-1 != startEventID {
814-
wtp.logger.Warn("Invalid PollForDecisionTaskResponse, nextEventID doesn't match startedEventID",
815-
zap.Int64("StartedEventID", startEventID),
816-
zap.Int64("NextEventID", nextEventID),
817-
)
818-
wtp.metricsScope.Counter(metrics.DecisionPollInvalidCounter).Inc(1)
811+
if nextEventID != 0 && startEventID != 0 {
812+
// first case is for normal decision, the second is for transient decision
813+
if nextEventID-1 != startEventID && nextEventID+1 != startEventID {
814+
wtp.logger.Warn("Invalid PollForDecisionTaskResponse, nextEventID doesn't match startedEventID",
815+
zap.Int64("StartedEventID", startEventID),
816+
zap.Int64("NextEventID", nextEventID),
817+
)
818+
wtp.metricsScope.Counter(metrics.DecisionPollInvalidCounter).Inc(1)
819+
} else {
820+
// in transient decision case, set nextEventID to be one more than startEventID in case
821+
// we can need to use the field to truncate history for decision task (check comments in newGetHistoryPageFunc)
822+
// this is safe as
823+
// - currently we are not using nextEventID for decision task
824+
// - for query task, startEventID is not assigned, so we won't reach here.
825+
nextEventID = startEventID + 1
826+
}
819827
}
820828
historyIterator := &historyIteratorImpl{
821829
nextPageToken: response.NextPageToken,

0 commit comments

Comments
 (0)