Skip to content

Commit 0896af9

Browse files
committed
fix race-condition bug in publish command
Signed-off-by: Paul Thiele <[email protected]>
1 parent 88aae9c commit 0896af9

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

internal/oci/resolver.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,13 @@ func Push(ctx context.Context, resolver remotes.Resolver, ref reference.Named, d
125125
if err != nil {
126126
return err
127127
}
128-
defer func() {
129-
_ = push.Close()
130-
}()
131128

132129
_, err = push.Write(descriptor.Data)
133-
return err
130+
if err != nil {
131+
// Close the writer on error since Commit won't be called
132+
_ = push.Close()
133+
return err
134+
}
135+
// Commit will close the writer
136+
return push.Commit(ctx, int64(len(descriptor.Data)), descriptor.Digest)
134137
}

0 commit comments

Comments
 (0)