Merge pull request #11698 from k8s-infra-cherrypick-robot/cherry-pick-11670-to-release/2.0

[release/2.0] Prevent panic on zero length push
This commit is contained in:
Derek McGowan 2025-04-16 08:57:13 +08:00 committed by GitHub
commit ea7be04cb4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -477,13 +477,15 @@ func (pw *pushWriter) Digest() digest.Digest {
func (pw *pushWriter) Commit(ctx context.Context, size int64, expected digest.Digest, opts ...content.Opt) error {
// Check whether read has already thrown an error
if _, err := pw.pipe.Write([]byte{}); err != nil && !errors.Is(err, io.ErrClosedPipe) {
return fmt.Errorf("pipe error before commit: %w", err)
if pw.pipe != nil {
if _, err := pw.pipe.Write([]byte{}); err != nil && !errors.Is(err, io.ErrClosedPipe) {
return fmt.Errorf("pipe error before commit: %w", err)
}
if err := pw.pipe.Close(); err != nil {
return err
}
}
if err := pw.pipe.Close(); err != nil {
return err
}
// TODO: timeout waiting for response
var resp *http.Response
select {