diff --git a/cache/blobs_linux.go b/cache/blobs_linux.go index 07c5bcffc9099..8ba03c1771ce6 100644 --- a/cache/blobs_linux.go +++ b/cache/blobs_linux.go @@ -45,6 +45,9 @@ func (sr *immutableRef) tryComputeOverlayBlob(ctx context.Context, lower, upper } defer func() { if cw != nil { + // after commit succ cw will be set to to nil, if cw isn't nil, error + // happened before commit, we should drop the content already written + cw.Truncate(0) if cerr := cw.Close(); cerr != nil { bklog.G(ctx).WithError(cerr).Warnf("failed to close writer %q", ref) }