Merge pull request #49265 from vvoland/export-ctx-cancellation

daemon/export: Stop when context is canceled
This commit is contained in:
Sebastiaan van Stijn
2025-01-13 19:41:21 +01:00
committed by GitHub

View File

@@ -71,11 +71,17 @@ func (daemon *Daemon) containerExport(ctx context.Context, ctr *container.Contai
return err
}
if err := ctx.Err(); err != nil {
return err
}
ctx, cancel := context.WithCancel(ctx)
defer cancel()
context.AfterFunc(ctx, func() {
_ = archv.Close()
})
// Stream the entire contents of the container (basically a volatile snapshot)
if _, err := io.Copy(out, archv); err != nil {
if err := ctx.Err(); err != nil {
return errdefs.Cancelled(err)
}
return err
}