Also move c.Lock() below containerd delete task, as it doesn't seem that
there is any necessity to hold the container lock while containerd is
killing the task.
This fixes a potential edge-case where containerd delete task hangs, and
thereafter all operations on the container would hang forever, as this
function is holding onto the container lock.
Signed-off-by: Cam <gh@sparr.email>
| ... | ... |
@@ -26,15 +26,17 @@ func (daemon *Daemon) setStateCounter(c *container.Container) {
|
| 26 | 26 |
|
| 27 | 27 |
func (daemon *Daemon) handleContainerExit(c *container.Container, e *libcontainerdtypes.EventInfo) error {
|
| 28 | 28 |
c.Lock() |
| 29 |
- |
|
| 30 |
- ec, et, err := daemon.containerd.DeleteTask(context.Background(), c.ID) |
|
| 29 |
+ ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) |
|
| 30 |
+ ec, et, err := daemon.containerd.DeleteTask(ctx, c.ID) |
|
| 31 |
+ cancel() |
|
| 31 | 32 |
if err != nil {
|
| 32 |
- logrus.WithError(err).Warnf("failed to delete container %s from containerd", c.ID)
|
|
| 33 |
+ logrus.WithError(err).WithField("container", c.ID).Warnf("failed to delete container from containerd")
|
|
| 33 | 34 |
} |
| 34 | 35 |
|
| 35 |
- ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) |
|
| 36 |
+ ctx, cancel = context.WithTimeout(context.Background(), 2*time.Second) |
|
| 36 | 37 |
c.StreamConfig.Wait(ctx) |
| 37 | 38 |
cancel() |
| 39 |
+ |
|
| 38 | 40 |
c.Reset(false) |
| 39 | 41 |
|
| 40 | 42 |
exitStatus := container.ExitStatus{
|