Browse code

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 <cpuguy83@gmail.com> (github: cpuguy83)

Brian Goff authored on 2014/09/25 11:46:57
Showing 2 changed files
... ...
@@ -664,7 +664,6 @@ func (cli *DockerCli) CmdStart(args ...string) error {
664 664
 	if encounteredError != nil {
665 665
 		if *openStdin || *attach {
666 666
 			cli.in.Close()
667
-			<-cErr
668 667
 		}
669 668
 		return encounteredError
670 669
 	}
671 670
new file mode 100644
... ...
@@ -0,0 +1,38 @@
0
+package main
1
+
2
+import (
3
+	"os/exec"
4
+	"testing"
5
+	"time"
6
+)
7
+
8
+// Regression test for https://github.com/docker/docker/issues/7843
9
+func TestStartAttachReturnsOnError(t *testing.T) {
10
+	defer deleteAllContainers()
11
+
12
+	cmd(t, "run", "-d", "--name", "test", "busybox")
13
+	cmd(t, "stop", "test")
14
+
15
+	// Expect this to fail because the above container is stopped, this is what we want
16
+	if _, err := runCommand(exec.Command(dockerBinary, "run", "-d", "--name", "test2", "--link", "test:test", "busybox")); err == nil {
17
+		t.Fatal("Expected error but got none")
18
+	}
19
+
20
+	ch := make(chan struct{})
21
+	go func() {
22
+		// Attempt to start attached to the container that won't start
23
+		// This should return an error immediately since the container can't be started
24
+		if _, err := runCommand(exec.Command(dockerBinary, "start", "-a", "test2")); err == nil {
25
+			t.Fatal("Expected error but got none")
26
+		}
27
+		close(ch)
28
+	}()
29
+
30
+	select {
31
+	case <-ch:
32
+	case <-time.After(time.Second):
33
+		t.Fatalf("Attach did not exit properly")
34
+	}
35
+
36
+	logDone("start - error on start with attach exits")
37
+}