From 2fd0edbff96984955d979a8f2fc8d75cb1d02481 Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Mon, 21 Nov 2022 15:06:38 -0700 Subject: [PATCH] environment(docker): fix timeout when sending a stop signal Previously, Docker would terminate the container when it's stop configuration was configured to send a signal to the container. This was due to Docker's API wanting the value as a duration string (`1s`) rather than a number, so our value of `-1` was being formatted to `0s` rather than `-1s` like we needed. Closes https://github.com/pterodactyl/panel/issues/4555 --- environment/docker/power.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/environment/docker/power.go b/environment/docker/power.go index 9b50274..13365d5 100644 --- a/environment/docker/power.go +++ b/environment/docker/power.go @@ -179,8 +179,12 @@ func (e *Environment) Stop(ctx context.Context) error { // Allow the stop action to run for however long it takes, similar to executing a command // and using a different logic pathway to wait for the container to stop successfully. - t := time.Duration(-1) - if err := e.client.ContainerStop(ctx, e.Id, &t); err != nil { + // + // Using a negative timeout here will allow the container to stop gracefully, + // rather than forcefully terminating it, this value MUST be at least 1 + // second, otherwise it will be ignored. + timeout := -1 * time.Second + if err := e.client.ContainerStop(ctx, e.Id, &timeout); err != nil { // If the container does not exist just mark the process as stopped and return without // an error. if client.IsErrNotFound(err) {