@@ -63,6 +63,7 @@ var log = logger.New(logrus.StandardLogger(), "env")
6363type Environment struct {
6464 Mu sync.RWMutex
6565 once sync.Once
66+ transitionMutex sync.RWMutex
6667 Sm * fsm.FSM
6768 name string
6869 id uid.ID
@@ -955,6 +956,13 @@ func (env *Environment) runTasksAsHooks(hooksToTrigger task.Tasks) (errorMap map
955956}
956957
957958func (env * Environment ) TryTransition (t Transition ) (err error ) {
959+ if ! env .transitionMutex .TryLock () {
960+ log .WithField ("partition" , env .id .String ()).
961+ Warnf ("environment transition attempt delayed: transition '%s' in progress. waiting for completion or failure" , env .currentTransition )
962+ env .transitionMutex .Lock ()
963+ }
964+ defer env .transitionMutex .Unlock ()
965+
958966 the .EventWriterWithTopic (topic .Environment ).WriteEvent (& pb.Ev_EnvironmentEvent {
959967 EnvironmentId : env .id .String (),
960968 State : env .Sm .Current (),
@@ -1171,11 +1179,17 @@ func (env *Environment) subscribeToWfState(taskman *task.Manager) {
11711179 Warn ("one of the critical tasks went into ERROR state, transitioning the environment into ERROR" )
11721180 err := env .TryTransition (NewGoErrorTransition (taskman ))
11731181 if err != nil {
1174- log .WithField ("partition" , env .id ).
1175- WithError (err ).
1176- WithField ("level" , infologger .IL_Devel ).
1177- Warn ("could not transition gently to ERROR, forcing it" )
1178- env .setState (wfState .String ())
1182+ if env .Sm .Current () == "ERROR" {
1183+ log .WithField ("partition" , env .id ).
1184+ WithField ("level" , infologger .IL_Devel ).
1185+ Info ("skipped requested transition to ERROR: environment already in ERROR state" )
1186+ } else {
1187+ log .WithField ("partition" , env .id ).
1188+ WithError (err ).
1189+ WithField ("level" , infologger .IL_Devel ).
1190+ Warn ("could not transition gently to ERROR, forcing it" )
1191+ env .setState (wfState .String ())
1192+ }
11791193 }
11801194 toStop := env .Workflow ().GetTasks ().Filtered (func (t * task.Task ) bool {
11811195 t .SetSafeToStop (true )
0 commit comments