Skip to content

Commit 90a7cda

Browse files
committed
attach: wait for exit code from ContainerWait
Such as with `docker run`, if a user CTRL-Cs while attached to a container, we should forward the signal and wait for the exit from `ContainerWait`, instead of just returning. Signed-off-by: Laura Brehm <[email protected]>
1 parent 788e996 commit 90a7cda

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

cli/command/container/attach.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ func RunAttach(ctx context.Context, dockerCLI command.Cli, containerID string, o
7272
apiClient := dockerCLI.Client()
7373

7474
// request channel to wait for client
75-
resultC, errC := apiClient.ContainerWait(ctx, containerID, "")
75+
waitCtx := context.WithoutCancel(ctx)
76+
resultC, errC := apiClient.ContainerWait(waitCtx, containerID, "")
7677

7778
c, err := inspectContainerAndCheckState(ctx, apiClient, containerID)
7879
if err != nil {
@@ -163,9 +164,6 @@ func getExitStatus(errC <-chan error, resultC <-chan container.WaitResponse) err
163164
return cli.StatusError{StatusCode: int(result.StatusCode)}
164165
}
165166
case err := <-errC:
166-
if errors.Is(err, context.Canceled) {
167-
return nil
168-
}
169167
return err
170168
}
171169

e2e/container/attach_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ func TestAttachInterrupt(t *testing.T) {
4949
c.Process.Signal(os.Interrupt)
5050

5151
_ = c.Wait()
52-
assert.Equal(t, c.ProcessState.ExitCode(), 0)
52+
assert.Equal(t, c.ProcessState.ExitCode(), 130)
5353
assert.Equal(t, d.String(), "")
5454
}

0 commit comments

Comments
 (0)