daemon: move default stop-timeout to containerStop()

This avoids having to determine what the default is in various
parts of the code. If no custom timeout is passed (nil), the
default will be used.

Also remove the named return variable from cleanupContainer(),
as it wasn't used.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2021-08-20 22:43:13 +02:00
parent f3bce92a24
commit 5edf9acf9c
4 changed files with 34 additions and 23 deletions

View File

@@ -97,7 +97,19 @@ func (daemon *Daemon) cleanupContainer(container *container.Container, config ty
// if stats are currently getting collected.
daemon.statsCollector.StopCollection(container)
if err := daemon.containerStop(container, 3); err != nil {
// stopTimeout is the number of seconds to wait for the container to stop
// gracefully before forcibly killing it.
//
// Why 3 seconds? The timeout specified here was originally added in commit
// 1615bb08c7c3fc6c4b22db0a633edda516f97cf0, which added a custom timeout to
// some commands, but lacking an option for a timeout on "docker rm", was
// hardcoded to 10 seconds. Commit 28fd289b448164b77affd8103c0d96fd8110daf9
// later on updated this to 3 seconds (but no background on that change).
//
// If you arrived here and know the answer, you earned yourself a picture
// of a cute animal of your own choosing.
var stopTimeout = 3
if err := daemon.containerStop(container, &stopTimeout); err != nil {
return err
}