From fc2e2234c614379d21c16e32c1b82e7819fc3eac Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Mon, 18 Apr 2016 11:48:28 -0700 Subject: [PATCH] Remove restart canceled error It should not be an error to call a common option to cancel restarts. Signed-off-by: Michael Crosby --- libcontainerd/container_linux.go | 5 ++++- restartmanager/restartmanager.go | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/libcontainerd/container_linux.go b/libcontainerd/container_linux.go index 1857874b32..6c740e49e3 100644 --- a/libcontainerd/container_linux.go +++ b/libcontainerd/container_linux.go @@ -9,6 +9,7 @@ import ( "github.com/Sirupsen/logrus" containerd "github.com/docker/containerd/api/grpc/types" + "github.com/docker/docker/restartmanager" "github.com/opencontainers/specs/specs-go" "golang.org/x/net/context" ) @@ -135,7 +136,9 @@ func (ctr *container) handleEvent(e *containerd.Event) error { logrus.Error(err) } }) - logrus.Error(err) + if err != restartmanager.ErrRestartCanceled { + logrus.Error(err) + } } else { ctr.start() } diff --git a/restartmanager/restartmanager.go b/restartmanager/restartmanager.go index 38730a9dd9..42c3245c51 100644 --- a/restartmanager/restartmanager.go +++ b/restartmanager/restartmanager.go @@ -1,6 +1,7 @@ package restartmanager import ( + "errors" "fmt" "sync" "time" @@ -13,6 +14,10 @@ const ( defaultTimeout = 100 * time.Millisecond ) +// ErrRestartCanceled is returned when the restart manager has been +// canceled and will no longer restart the container. +var ErrRestartCanceled = errors.New("restart canceled") + // RestartManager defines object that controls container restarting rules. type RestartManager interface { Cancel() error @@ -54,7 +59,7 @@ func (rm *restartManager) ShouldRestart(exitCode uint32, hasBeenManuallyStopped }() if rm.canceled { - return false, nil, fmt.Errorf("restartmanager canceled") + return false, nil, ErrRestartCanceled } if rm.active { @@ -95,7 +100,7 @@ func (rm *restartManager) ShouldRestart(exitCode uint32, hasBeenManuallyStopped go func() { select { case <-rm.cancel: - ch <- fmt.Errorf("restartmanager canceled") + ch <- ErrRestartCanceled close(ch) case <-time.After(rm.timeout): rm.Lock()