From 381d593d04fc46dac5b202d047981e15183c5ed1 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Fri, 10 Jan 2014 16:18:15 -0800 Subject: [PATCH] Fix race in cleanup Docker-DCO-1.1-Signed-off-by: Michael Crosby (github: crosbymichael) --- container.go | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/container.go b/container.go index 80f9e34ac2..856ee352d6 100644 --- a/container.go +++ b/container.go @@ -379,12 +379,14 @@ func (container *Container) Attach(stdin io.ReadCloser, stdinCloser io.Closer, s if container.Config.StdinOnce && !container.Config.Tty { defer cStdin.Close() } else { - if cStdout != nil { - defer cStdout.Close() - } - if cStderr != nil { - defer cStderr.Close() - } + defer func() { + if cStdout != nil { + cStdout.Close() + } + if cStderr != nil { + cStderr.Close() + } + }() } if container.Config.Tty { _, err = utils.CopyEscapable(cStdin, stdin) @@ -480,12 +482,15 @@ func (container *Container) Attach(stdin io.ReadCloser, stdinCloser io.Closer, s } return utils.Go(func() error { - if cStdout != nil { - defer cStdout.Close() - } - if cStderr != nil { - defer cStderr.Close() - } + defer func() { + if cStdout != nil { + cStdout.Close() + } + if cStderr != nil { + cStderr.Close() + } + }() + // FIXME: how to clean up the stdin goroutine without the unwanted side effect // of closing the passed stdin? Add an intermediary io.Pipe? for i := 0; i < nJobs; i += 1 {