Browse code

Merge pull request #14547 from duglin/ErrDeadExec

Return 404 on exec-inspect when container is dead but exec is still around

Alexander Morozov authored on 2015/07/28 02:46:32
Showing 2 changed files
... ...
@@ -89,7 +89,16 @@ func (d *Daemon) registerExecCommand(execConfig *execConfig) {
89 89
 }
90 90
 
91 91
 func (d *Daemon) getExecConfig(name string) (*execConfig, error) {
92
-	if execConfig := d.execCommands.Get(name); execConfig != nil {
92
+	execConfig := d.execCommands.Get(name)
93
+
94
+	// If the exec is found but its container is not in the daemon's list of
95
+	// containers then it must have been delete, in which case instead of
96
+	// saying the container isn't running, we should return a 404 so that
97
+	// the user sees the same error now that they will after the
98
+	// 5 minute clean-up loop is run which erases old/dead execs.
99
+
100
+	if execConfig != nil && d.containers.Get(execConfig.Container.ID) != nil {
101
+
93 102
 		if !execConfig.Container.IsRunning() {
94 103
 			return nil, fmt.Errorf("Container %s is not running", execConfig.Container.ID)
95 104
 		}
... ...
@@ -369,6 +369,17 @@ func (s *DockerSuite) TestInspectExecID(c *check.C) {
369 369
 	if sc != http.StatusOK {
370 370
 		c.Fatalf("received status != 200 OK: %d\n%s", sc, body)
371 371
 	}
372
+
373
+	// Now delete the container and then an 'inspect' on the exec should
374
+	// result in a 404 (not 'container not running')
375
+	out, ec := dockerCmd(c, "rm", "-f", id)
376
+	if ec != 0 {
377
+		c.Fatalf("error removing container: %s", out)
378
+	}
379
+	sc, body, err = sockRequest("GET", "/exec/"+execID+"/json", nil)
380
+	if sc != http.StatusNotFound {
381
+		c.Fatalf("received status != 404: %s\n%s", sc, body)
382
+	}
372 383
 }
373 384
 
374 385
 func (s *DockerSuite) TestLinksPingLinkedContainersOnRename(c *check.C) {