From 6eb5720233ddbf00a614e82524ade35a0e3cfc5c Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 22 Mar 2021 13:20:40 +0100 Subject: [PATCH 1/2] Fix daemon.getExecConfig(): not using typed errNotRunning() error This makes daemon.getExecConfig return a errdefs.Conflict() error if the container is not running. This was originally the case, but a refactor of this code changed the typed error (`derr.ErrorCodeContainerNotRunning`) to a non-typed error; a793564b2591035aec5412fbcbcccf220c773a4c Signed-off-by: Sebastiaan van Stijn --- daemon/exec.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daemon/exec.go b/daemon/exec.go index 78a593a6e2..302842196b 100644 --- a/daemon/exec.go +++ b/daemon/exec.go @@ -59,7 +59,7 @@ func (daemon *Daemon) getExecConfig(name string) (*exec.Config, error) { return nil, containerNotFound(name) } if !ctr.IsRunning() { - return nil, fmt.Errorf("Container %s is not running: %s", ctr.ID, ctr.State.String()) + return nil, errNotRunning(ctr.ID) } if ctr.IsPaused() { return nil, errExecPaused(ctr.ID) From a432eb4b3a0d06675889153e2993ae8ba8dc9149 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 13 Mar 2021 21:41:32 +0100 Subject: [PATCH 2/2] ContainerExecStart(): don't wrap getExecConfig() errors, and prevent panic daemon.getExecConfig() already returns typed errors; by wrapping those errors we may loose the actual reason for failures. Changing the error-type was originally added in 2d43d93410c29cec87deb9cd940c3b2a8af5fbbb, but I think it was not intentional to ignore already-typed errors. It was later refactored in a793564b2591035aec5412fbcbcccf220c773a4c, which added helper functions to create these errors, but kept the same behavior. Also adds error-handling to prevent a panic in situations where (although unlikely) `daemon.containers.Get()` would not return a container. Signed-off-by: Sebastiaan van Stijn --- daemon/exec.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/daemon/exec.go b/daemon/exec.go index 302842196b..b466d610fe 100644 --- a/daemon/exec.go +++ b/daemon/exec.go @@ -158,7 +158,7 @@ func (daemon *Daemon) ContainerExecStart(ctx context.Context, name string, stdin ec, err := daemon.getExecConfig(name) if err != nil { - return errExecNotFound(name) + return err } ec.Lock() @@ -176,6 +176,9 @@ func (daemon *Daemon) ContainerExecStart(ctx context.Context, name string, stdin ec.Unlock() c := daemon.containers.Get(ec.ContainerID) + if c == nil { + return containerNotFound(ec.ContainerID) + } logrus.Debugf("starting exec command %s in container %s", ec.ID, c.ID) attributes := map[string]string{ "execID": ec.ID,