Browse Source

fix race-condition bug in publish command

Signed-off-by: Paul Thiele <[email protected]>
Paul Thiele 2 months ago
parent
commit
157617480a
1 changed files with 7 additions and 4 deletions
  1. 7 4
      internal/oci/resolver.go

+ 7 - 4
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)
 }