Skip to content

Commit 5e5d083

Browse files
committed
[core] Wait for 500ms for ERROR states to settle before GO_ERROR/STOP
1 parent 6d45479 commit 5e5d083

File tree

1 file changed

+31
-24
lines changed

1 file changed

+31
-24
lines changed

core/environment/environment.go

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -734,36 +734,43 @@ func (env *Environment) subscribeToWfState(taskman *task.Manager) {
734734

735735
wfState := wf.GetState()
736736
if wfState != task.ERROR {
737+
handlingError := false
737738
WORKFLOW_STATE_LOOP:
738739
for {
739740
select {
740741
case wfState = <-notify:
741742
if wfState == task.ERROR {
742-
err := env.TryTransition(NewGoErrorTransition(taskman))
743-
if err != nil {
744-
log.WithField("partition", env.id).
745-
WithError(err).
746-
WithField("level", infologger.IL_Devel).
747-
Warn("could not transition gently to ERROR, forcing it")
748-
env.setState(wfState.String())
743+
if !handlingError {
744+
handlingError = true
745+
746+
time.AfterFunc(500*time.Millisecond, func() { // wait 0.5s for any other tasks to go to ERROR/INACTIVE
747+
err := env.TryTransition(NewGoErrorTransition(taskman))
748+
if err != nil {
749+
log.WithField("partition", env.id).
750+
WithError(err).
751+
WithField("level", infologger.IL_Devel).
752+
Warn("could not transition gently to ERROR, forcing it")
753+
env.setState(wfState.String())
754+
}
755+
toStop := env.Workflow().GetTasks().Filtered(func(t *task.Task) bool {
756+
t.SetSafeToStop(true)
757+
return t.IsSafeToStop()
758+
})
759+
if len(toStop) > 0 {
760+
taskmanMessage := task.NewTransitionTaskMessage(
761+
toStop,
762+
task.RUNNING.String(),
763+
task.STOP.String(),
764+
task.CONFIGURED.String(),
765+
nil,
766+
env.Id(),
767+
)
768+
taskman.MessageChannel <- taskmanMessage
769+
<-env.stateChangedCh
770+
}
771+
})
772+
break WORKFLOW_STATE_LOOP
749773
}
750-
toStop := env.Workflow().GetTasks().Filtered(func(t *task.Task) bool {
751-
t.SetSafeToStop(true)
752-
return t.IsSafeToStop()
753-
})
754-
if len(toStop) > 0 {
755-
taskmanMessage := task.NewTransitionTaskMessage(
756-
toStop,
757-
task.RUNNING.String(),
758-
task.STOP.String(),
759-
task.CONFIGURED.String(),
760-
nil,
761-
env.Id(),
762-
)
763-
taskman.MessageChannel <- taskmanMessage
764-
<-env.stateChangedCh
765-
}
766-
break WORKFLOW_STATE_LOOP
767774
}
768775
if wfState == task.DONE {
769776
break WORKFLOW_STATE_LOOP

0 commit comments

Comments
 (0)