From 7ac8aea1b9136d2f2760d2474ba76c1e21925639 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 21 Jan 2014 18:05:03 -0800 Subject: [PATCH] Fix issue with exit code in non-tty mode. Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes (github: creack) Upstream-commit: fd38de2818d959a9f5591537515e923a3ac56632 Component: engine --- components/engine/commands.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/components/engine/commands.go b/components/engine/commands.go index a5d7c9100a..3724a0aaed 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -2168,9 +2168,18 @@ func (cli *DockerCli) CmdRun(args ...string) error { return err } } else { - // No Autoremove: Simply retrieve the exit code - if _, status, err = getExitCode(cli, runResult.ID); err != nil { - return err + if !config.Tty { + // In non-tty mode, we can't dettach, so we know we need to wait. + if status, err = waitForExit(cli, runResult.ID); err != nil { + return err + } + } else { + // In TTY mode, there is a race. If the process dies too slowly, the state can be update after the getExitCode call + // and result in a wrong exit code. + // No Autoremove: Simply retrieve the exit code + if _, status, err = getExitCode(cli, runResult.ID); err != nil { + return err + } } } if status != 0 {