Potential fix for servers being marked as stopping after being marked as offline

This commit is contained in:
Matthew Penner 2021-01-07 19:32:15 -07:00
parent 1d36811dfe
commit 66c9be357c
2 changed files with 8 additions and 4 deletions

View File

@ -60,8 +60,10 @@ func (e *Environment) Attach() error {
go func() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
defer e.stream.Close()
defer func() {
e.stream.Close()
e.SetState(environment.ProcessOfflineState)
e.SetStream(nil)
}()
@ -78,7 +80,7 @@ func (e *Environment) Attach() error {
// Block the completion of this routine until the container is no longer running. This allows
// the pollResources function to run until it needs to be stopped. Because the container
// can be polled for resource usage, even when sropped, we need to have this logic present
// can be polled for resource usage, even when stopped, we need to have this logic present
// in order to cancel the context and therefore stop the routine that is spawned.
ok, err := e.client.ContainerWait(ctx, e.Id, container.WaitConditionNotRunning)
select {
@ -272,6 +274,8 @@ func (e *Environment) Destroy() error {
Force: true,
})
e.SetState(environment.ProcessOfflineState)
// Don't trigger a destroy failure if we try to delete a container that does not
// exist on the system. We're just a step ahead of ourselves in that case.
//
@ -280,8 +284,6 @@ func (e *Environment) Destroy() error {
return nil
}
e.SetState(environment.ProcessOfflineState)
return err
}

View File

@ -64,9 +64,11 @@ func (s *Server) StartEventListeners() {
// to terminate again.
if s.Environment.State() != environment.ProcessStoppingState {
s.Environment.SetState(environment.ProcessStoppingState)
go func() {
s.Log().Warn("stopping server instance, violating throttle limits")
s.PublishConsoleOutputFromDaemon("Your server is being stopped for outputting too much data in a short period of time.")
// Completely skip over server power actions and terminate the running instance. This gives the
// server 15 seconds to finish stopping gracefully before it is forcefully terminated.
if err := s.Environment.WaitForStop(config.Get().Throttles.StopGracePeriod, true); err != nil {