From 9ae9d7db574083ce6233b33e8b0bbefb219d7fe6 Mon Sep 17 00:00:00 2001 From: Brian Goff Date: Wed, 24 Sep 2014 22:46:57 -0400 Subject: [PATCH] Fix #7843 When doing `docker start -a` on a container that won't start, terminal was getting stuck on the attach, even after container removal. Docker-DCO-1.1-Signed-off-by: Brian Goff (github: cpuguy83) --- api/client/commands.go | 1 - integration-cli/docker_cli_start_test.go | 38 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 integration-cli/docker_cli_start_test.go diff --git a/api/client/commands.go b/api/client/commands.go index fa0f69f3d6..eeb73fa19e 100644 --- a/api/client/commands.go +++ b/api/client/commands.go @@ -664,7 +664,6 @@ func (cli *DockerCli) CmdStart(args ...string) error { if encounteredError != nil { if *openStdin || *attach { cli.in.Close() - <-cErr } return encounteredError } diff --git a/integration-cli/docker_cli_start_test.go b/integration-cli/docker_cli_start_test.go new file mode 100644 index 0000000000..18ad96aef1 --- /dev/null +++ b/integration-cli/docker_cli_start_test.go @@ -0,0 +1,38 @@ +package main + +import ( + "os/exec" + "testing" + "time" +) + +// Regression test for https://github.com/docker/docker/issues/7843 +func TestStartAttachReturnsOnError(t *testing.T) { + defer deleteAllContainers() + + cmd(t, "run", "-d", "--name", "test", "busybox") + cmd(t, "stop", "test") + + // Expect this to fail because the above container is stopped, this is what we want + if _, err := runCommand(exec.Command(dockerBinary, "run", "-d", "--name", "test2", "--link", "test:test", "busybox")); err == nil { + t.Fatal("Expected error but got none") + } + + ch := make(chan struct{}) + go func() { + // Attempt to start attached to the container that won't start + // This should return an error immediately since the container can't be started + if _, err := runCommand(exec.Command(dockerBinary, "start", "-a", "test2")); err == nil { + t.Fatal("Expected error but got none") + } + close(ch) + }() + + select { + case <-ch: + case <-time.After(time.Second): + t.Fatalf("Attach did not exit properly") + } + + logDone("start - error on start with attach exits") +}