Skip to content

Commit 025a3ed

Browse files
knopers8teo
authored andcommitted
[core] OCTRL-911 do not teardown an environment in DONE
This is a fix to avoid running a second teardown attempt after a successful one. This could have happened if the 2nd teardown request was received while the 1st teardown attempt would be still ongoing. In principle #600 was already enough to avoid concurrency issues and I could not make the core misbehave with it, but this commit attempts to make the behaviour somewhat more correct. I hesitated to set the state as DONE if TeardownEnvironment returns earlier with an error, since this does not remove given environment from the list of enviroments, thus technically it is still available for more teardown attempts. On another hand, this contradicts the already published kafka events, which advertize the env state as DONE even when it ends with error and the state is not set anyway.
1 parent 48ea72a commit 025a3ed

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

core/environment/manager.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,9 @@ func (envs *Manager) TeardownEnvironment(environmentId uid.ID, force bool) error
589589
}
590590
defer env.transitionMutex.Unlock()
591591

592+
if env.CurrentState() == "DONE" {
593+
return errors.New("attempting to teardown an environment which is already in DONE, doing nothing")
594+
}
592595
if env.CurrentState() != "STANDBY" && env.CurrentState() != "DEPLOYED" && !force {
593596
return errors.New(fmt.Sprintf("cannot teardown environment in state %s", env.CurrentState()))
594597
}
@@ -851,6 +854,7 @@ func (envs *Manager) TeardownEnvironment(environmentId uid.ID, force bool) error
851854
return err
852855
}
853856

857+
env.setState("DONE")
854858
env.sendEnvironmentEvent(&event.EnvironmentEvent{EnvironmentID: env.Id().String(), Message: "teardown complete", State: "DONE"})
855859

856860
log.WithField("method", "TeardownEnvironment").

0 commit comments

Comments
 (0)