Delete on increment and add a safety guard

This commit is contained in:
Alex Dadgar 2017-02-27 20:23:21 -08:00
parent 3dc0e38feb
commit 48ab2a6c6a

View file

@ -203,6 +203,7 @@ func (d *dockerCoordinator) IncrementImageReference(id, image string) {
if cancel, ok := d.deleteFuture[id]; ok {
d.logger.Printf("[DEBUG] driver.docker: cancelling removal of image %q", image)
cancel()
delete(d.deleteFuture, id)
}
d.imageLock.Unlock()
}
@ -229,6 +230,13 @@ func (d *dockerCoordinator) RemoveImage(id string) {
return
}
// This should never be the case but we safefty guard so we don't leak a
// cancel.
if cancel, ok := d.deleteFuture[id]; ok {
d.logger.Printf("[ERR] driver.docker: image id %q has lingering delete future", id)
cancel()
}
// Setup a future to delete the image
ctx, cancel := context.WithCancel(context.Background())
d.deleteFuture[id] = cancel