Skip to content

Commit da34f4a

Browse files
authored
fix sticky state (#303)
1 parent 1bc4f70 commit da34f4a

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

internal_task_handlers.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,9 @@ func (wth *workflowTaskHandlerImpl) getOrCreateWorkflowContext(task *s.PollForDe
469469
workflowContext.Lock()
470470
if h.Events[0].GetEventId() != workflowContext.previousStartedEventID+1 {
471471
// cached state is missing events, we need to discard the cached state and rebuild one.
472-
wth.logger.Warn("Cached sticky workflow state is missing some events.",
472+
wth.logger.Debug("Cached sticky workflow state is stalled.",
473+
zap.String(tagWorkflowID, task.WorkflowExecution.GetWorkflowId()),
474+
zap.String(tagRunID, runID),
473475
zap.Int64("CachedPreviousStartedEventID", workflowContext.previousStartedEventID),
474476
zap.Int64("TaskFirstEventID", h.Events[0].GetEventId()),
475477
zap.Int64("TaskStartedEventID", task.GetStartedEventId()),
@@ -500,20 +502,23 @@ func (wth *workflowTaskHandlerImpl) getOrCreateWorkflowContext(task *s.PollForDe
500502
}
501503
workflowContext.Lock()
502504
}
503-
if task.Query == nil {
504-
workflowContext.previousStartedEventID = task.GetStartedEventId()
505-
}
506-
507505
// It is possible that 2 threads (one for decision task and one for query task) that both are getting this same
508506
// cached workflowContext. If one task finished with err, it would destroy the cached state. In that case, the
509507
// second task needs to reset the cache state and start from beginning of the history.
510508
if workflowContext.isDestroyed() {
511509
workflowContext.resetWorkflowState()
512-
if h, err = resetHistory(task, historyIterator); err != nil {
513-
return
510+
// reset history events if necessary
511+
if h.Events[0].GetEventType() != s.EventTypeWorkflowExecutionStarted {
512+
if h, err = resetHistory(task, historyIterator); err != nil {
513+
return
514+
}
514515
}
515516
}
516517

518+
if task.Query == nil {
519+
workflowContext.previousStartedEventID = task.GetStartedEventId()
520+
}
521+
517522
return
518523
}
519524

0 commit comments

Comments
 (0)