Skip to content

Commit 68d0a9e

Browse files
author
Mahmood Ali
authored
Merge pull request #7749 from hashicorp/b-docker-panic
driver/docker: protect against nil container
2 parents 482804d + 7f29912 commit 68d0a9e

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
BUG FIXES:
44

55
* core: Fixed a bug that only ran a task `shutdown_delay` if the task had a registered service [[GH-7663](https://github.com/hashicorp/nomad/issues/7663)]
6+
* driver/docker: Fixed a bug where retrying failed docker creation may in rare cases trigger a panic [[GH-7749](https://github.com/hashicorp/nomad/issues/7749)]
67
* vault: Upgrade http2 library to fix Vault API calls that fail with `http2: no cached connection was available` [[GH-7673](https://github.com/hashicorp/nomad/issues/7673)]
78

89
## 0.11.0 (April 8, 2020)

drivers/docker/driver.go

+15-10
Original file line numberDiff line numberDiff line change
@@ -439,16 +439,21 @@ CREATE:
439439
return container, nil
440440
}
441441

442-
// Delete matching containers
443-
err = client.RemoveContainer(docker.RemoveContainerOptions{
444-
ID: container.ID,
445-
Force: true,
446-
})
447-
if err != nil {
448-
d.logger.Error("failed to purge container", "container_id", container.ID)
449-
return nil, recoverableErrTimeouts(fmt.Errorf("Failed to purge container %s: %s", container.ID, err))
450-
} else {
451-
d.logger.Info("purged container", "container_id", container.ID)
442+
// Purge conflicting container if found.
443+
// If container is nil here, the conflicting container was
444+
// deleted in our check here, so retry again.
445+
if container != nil {
446+
// Delete matching containers
447+
err = client.RemoveContainer(docker.RemoveContainerOptions{
448+
ID: container.ID,
449+
Force: true,
450+
})
451+
if err != nil {
452+
d.logger.Error("failed to purge container", "container_id", container.ID)
453+
return nil, recoverableErrTimeouts(fmt.Errorf("Failed to purge container %s: %s", container.ID, err))
454+
} else {
455+
d.logger.Info("purged container", "container_id", container.ID)
456+
}
452457
}
453458

454459
if attempted < 5 {

0 commit comments

Comments
 (0)