From 0896af9370234b5495206ba49f61588bff80833f Mon Sep 17 00:00:00 2001 From: Paul Thiele Date: Thu, 16 Oct 2025 08:55:54 +0200 Subject: [PATCH] fix race-condition bug in publish command Signed-off-by: Paul Thiele --- internal/oci/resolver.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/internal/oci/resolver.go b/internal/oci/resolver.go index a71d335ba44..0f44f947006 100644 --- a/internal/oci/resolver.go +++ b/internal/oci/resolver.go @@ -125,10 +125,13 @@ func Push(ctx context.Context, resolver remotes.Resolver, ref reference.Named, d if err != nil { return err } - defer func() { - _ = push.Close() - }() _, err = push.Write(descriptor.Data) - return err + if err != nil { + // Close the writer on error since Commit won't be called + _ = push.Close() + return err + } + // Commit will close the writer + return push.Commit(ctx, int64(len(descriptor.Data)), descriptor.Digest) }