Skip to content

Commit 4e4721f

Browse files
http2 throws custom error Content-Length shorter handle it
We should internally handle when http2 input stream has smaller content than its content-length header Upstream issue reported golang/go#30648 This a change which we need to handle internally until Go fixes it correctly, till now our code doesn't expect a custom error to be returned.
1 parent f4879ed commit 4e4721f

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

cmd/fs-v1-helpers.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -344,20 +344,23 @@ func fsCreateFile(ctx context.Context, filePath string, reader io.Reader, buf []
344344
var bytesWritten int64
345345
if buf != nil {
346346
bytesWritten, err = io.CopyBuffer(writer, reader, buf)
347-
if err != nil {
348-
if err != io.ErrUnexpectedEOF {
349-
logger.LogIf(ctx, err)
350-
}
351-
return 0, err
352-
}
353347
} else {
354348
bytesWritten, err = io.Copy(writer, reader)
355-
if err != nil {
349+
}
350+
if fallocSize > 0 {
351+
if bytesWritten < fallocSize {
352+
err = io.ErrUnexpectedEOF
353+
}
354+
if bytesWritten > fallocSize {
355+
err = io.ErrUnexpectedEOF
356+
}
357+
}
358+
if err != nil {
359+
if err != io.ErrUnexpectedEOF {
356360
logger.LogIf(ctx, err)
357-
return 0, err
358361
}
362+
return 0, err
359363
}
360-
361364
return bytesWritten, nil
362365
}
363366

cmd/posix.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,16 +1091,13 @@ func (s *posix) CreateFile(volume, path string, fileSize int64, r io.Reader) (er
10911091
defer s.pool.Put(bufp)
10921092

10931093
n, err := io.CopyBuffer(w, r, *bufp)
1094-
if err != nil {
1095-
return err
1096-
}
10971094
if n < fileSize {
10981095
return errLessData
10991096
}
11001097
if n > fileSize {
11011098
return errMoreData
11021099
}
1103-
return nil
1100+
return err
11041101
}
11051102

11061103
func (s *posix) WriteAll(volume, path string, buf []byte) (err error) {

0 commit comments

Comments
 (0)