Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker: fix bug in waiting for container to exit #24081

Merged
merged 1 commit into from
Sep 30, 2024
Merged
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
16 changes: 11 additions & 5 deletions drivers/docker/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,12 @@ func (h *taskHandle) run() {

h.startCpusetFixer()

ctx, cancel := context.WithTimeout(context.Background(), dockerTimeout)
defer cancel()

var werr error
var exitCode containerapi.WaitResponse
exitCodeC, errC := h.infinityClient.ContainerWait(ctx, h.containerID, containerapi.WaitConditionNotRunning)
// this needs to use the background context because the container can
// outlive Nomad itself
exitCodeC, errC := h.infinityClient.ContainerWait(
context.Background(), h.containerID, containerapi.WaitConditionNotRunning)

select {
case exitCode = <-exitCodeC:
Expand All @@ -308,6 +308,9 @@ func (h *taskHandle) run() {
h.logger.Error("failed to wait for container; already terminated")
}

ctx, inspectCancel := context.WithTimeout(context.Background(), 10*time.Second)
defer inspectCancel()
Comment on lines +311 to +312
Copy link
Member Author

Choose a reason for hiding this comment

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

The dockerTimeout of 5m seems ridiculous for these two API calls, which should return immediately as far as I can tell. Even 10s seems like a lot, but I don't really know what we can expect out of Docker's API here.


container, ierr := h.dockerClient.ContainerInspect(ctx, h.containerID)
oom := false
if ierr != nil {
Expand All @@ -331,7 +334,10 @@ func (h *taskHandle) run() {
close(h.doneCh)

// Stop the container just incase the docker daemon's wait returned
// incorrectly.
// incorrectly. Container should have exited by now so kill_timeout can be
// ignored.
ctx, stopCancel := context.WithTimeout(context.Background(), 10*time.Second)
defer stopCancel()
if err := h.dockerClient.ContainerStop(ctx, h.containerID, containerapi.StopOptions{
Timeout: pointer.Of(0),
}); err != nil {
Expand Down
Loading