From 66c9be357c5944f167a4c4e041c89f0bc4bda33e Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Thu, 7 Jan 2021 19:32:15 -0700 Subject: [PATCH] Potential fix for servers being marked as stopping after being marked as offline --- environment/docker/container.go | 10 ++++++---- server/listeners.go | 2 ++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/environment/docker/container.go b/environment/docker/container.go index 58a728d..914ed0b 100644 --- a/environment/docker/container.go +++ b/environment/docker/container.go @@ -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 } diff --git a/server/listeners.go b/server/listeners.go index 9717879..8318a75 100644 --- a/server/listeners.go +++ b/server/listeners.go @@ -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 {