Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions cli/command/container/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ func runContainer(dockerCli command.Cli, opts *runOptions, copts *containerOptio
defer close()
}

statusChan := waitExitOrRemoved(ctx, dockerCli, createResponse.ID, copts.autoRemove)
// We don't need to wait if we're not attaching.
var statusChan <-chan int
if attach {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if attach is right here, but I really don't understand config.Attach* at all anyway. Right now we might get a panic if you do -a stdin (or in some of the error paths) because we might read from a nil chan -- but I don't see a nice way of solving that.

A simpler way of stopping the issue behind this problem is to just drop the logging code from waitExitOrRemoved.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading from a nil chain would block forever, not panic.
So we either need another if attach before reading below (so as not to block forever) or make a channel and close it...

I agree waitExitOrRemoved should not be logging.
It could return a channel can handle both exit status and error messages.

I think removing logging, or some way to gate logging, might be a better approach.

statusChan = waitExitOrRemoved(ctx, dockerCli, createResponse.ID, copts.autoRemove)
}

//start the container
if err := client.ContainerStart(ctx, createResponse.ID, types.ContainerStartOptions{}); err != nil {
Expand All @@ -186,7 +190,7 @@ func runContainer(dockerCli command.Cli, opts *runOptions, copts *containerOptio
return runStartContainerErr(err)
}

if (config.AttachStdin || config.AttachStdout || config.AttachStderr) && config.Tty && dockerCli.Out().IsTerminal() {
if attach && config.Tty && dockerCli.Out().IsTerminal() {
if err := MonitorTtySize(ctx, dockerCli, createResponse.ID, false); err != nil {
fmt.Fprintln(stderr, "Error monitoring TTY size:", err)
}
Expand Down