diff --git a/core/environment/environment.go b/core/environment/environment.go index fcddf89d..4af1f0a6 100644 --- a/core/environment/environment.go +++ b/core/environment/environment.go @@ -155,7 +155,11 @@ func newEnvironment(userVars map[string]string, newId uid.ID) (env *Environment, }, fsm.Callbacks{ "before_event": func(_ context.Context, e *fsm.Event) { + + env.Mu.Lock() env.currentTransition = e.Event + env.Mu.Unlock() + trigger := fmt.Sprintf("before_%s", e.Event) the.EventWriterWithTopic(topic.Environment).WriteEvent(&pb.Ev_EnvironmentEvent{ @@ -382,7 +386,11 @@ func newEnvironment(userVars map[string]string, newId uid.ID) (env *Environment, }).Debug("environment.sm entering state") }, "after_event": func(_ context.Context, e *fsm.Event) { - defer func() { env.currentTransition = "" }() + defer func() { + env.Mu.Lock() + env.currentTransition = "" + env.Mu.Unlock() + }() trigger := fmt.Sprintf("after_%s", e.Event) diff --git a/core/environment/manager.go b/core/environment/manager.go index bff7ce4a..9778dbc3 100644 --- a/core/environment/manager.go +++ b/core/environment/manager.go @@ -469,7 +469,9 @@ func (envs *Manager) TeardownEnvironment(environmentId uid.ID, force bool) error return errors.New(fmt.Sprintf("cannot teardown environment in state %s", env.CurrentState())) } + env.Mu.Lock() env.currentTransition = "DESTROY" + env.Mu.Unlock() err = env.handleHooks(env.Workflow(), "leave_"+env.CurrentState()) if err != nil {