[#149] client: Fix false io.ErrUnexpectedEOF return

In previous implementation `Close` method of `ObjectReader` /
`ObjectRangeReader` could incorrectly return `io.ErrUnexpectedEOF` of
payload wasn't read by `Read` method (in this case
`remainingPayloadLen` state var is not updated).

Return `io.ErrUnexpectedEOF` from `Read` method only.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2022-02-24 14:44:49 +03:00 committed by LeL
parent 2adbe29f7f
commit b5874778e9

View file

@ -223,9 +223,11 @@ func (x *ObjectReader) close(ignoreEOF bool) (*ResObjectGet, error) {
if x.ctxCall.err != nil { if x.ctxCall.err != nil {
if !errors.Is(x.ctxCall.err, io.EOF) { if !errors.Is(x.ctxCall.err, io.EOF) {
return nil, x.ctxCall.err return nil, x.ctxCall.err
} else if x.remainingPayloadLen > 0 {
return nil, io.ErrUnexpectedEOF
} else if !ignoreEOF { } else if !ignoreEOF {
if x.remainingPayloadLen > 0 {
return nil, io.ErrUnexpectedEOF
}
return nil, io.EOF return nil, io.EOF
} }
} }
@ -663,9 +665,11 @@ func (x *ObjectRangeReader) close(ignoreEOF bool) (*ResObjectRange, error) {
if x.ctxCall.err != nil { if x.ctxCall.err != nil {
if !errors.Is(x.ctxCall.err, io.EOF) { if !errors.Is(x.ctxCall.err, io.EOF) {
return nil, x.ctxCall.err return nil, x.ctxCall.err
} else if x.remainingPayloadLen > 0 {
return nil, io.ErrUnexpectedEOF
} else if !ignoreEOF { } else if !ignoreEOF {
if x.remainingPayloadLen > 0 {
return nil, io.ErrUnexpectedEOF
}
return nil, io.EOF return nil, io.EOF
} }
} }