Skip to content

Commit

Permalink
[core] OCTRL-911 do not teardown an environment in DONE
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
knopers8 authored and teo committed Aug 1, 2024
1 parent 48ea72a commit 025a3ed
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/environment/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,9 @@ func (envs *Manager) TeardownEnvironment(environmentId uid.ID, force bool) error
}
defer env.transitionMutex.Unlock()

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

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

log.WithField("method", "TeardownEnvironment").
Expand Down

0 comments on commit 025a3ed

Please sign in to comment.