1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

handleContainerExit: put a timeout on containerd DeleteTask

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>
This commit is contained in:
Cam 2020-11-02 19:56:58 -08:00
parent b6bfff2a62
commit 05c20a6e1c
No known key found for this signature in database
GPG key ID: EE812B08DF32F58C

View file

@ -26,15 +26,17 @@ func (daemon *Daemon) setStateCounter(c *container.Container) {
func (daemon *Daemon) handleContainerExit(c *container.Container, e *libcontainerdtypes.EventInfo) error { func (daemon *Daemon) handleContainerExit(c *container.Container, e *libcontainerdtypes.EventInfo) error {
c.Lock() c.Lock()
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
ec, et, err := daemon.containerd.DeleteTask(context.Background(), c.ID) ec, et, err := daemon.containerd.DeleteTask(ctx, c.ID)
cancel()
if err != nil { if err != nil {
logrus.WithError(err).Warnf("failed to delete container %s from containerd", c.ID) logrus.WithError(err).WithField("container", c.ID).Warnf("failed to delete container from containerd")
} }
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) ctx, cancel = context.WithTimeout(context.Background(), 2*time.Second)
c.StreamConfig.Wait(ctx) c.StreamConfig.Wait(ctx)
cancel() cancel()
c.Reset(false) c.Reset(false)
exitStatus := container.ExitStatus{ exitStatus := container.ExitStatus{