From b5874778e99832cb592aa752877ba4a858ab75e4 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 24 Feb 2022 14:44:49 +0300 Subject: [PATCH] [#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 --- client/object_get.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/client/object_get.go b/client/object_get.go index 98a4fbf..ac43c86 100644 --- a/client/object_get.go +++ b/client/object_get.go @@ -223,9 +223,11 @@ func (x *ObjectReader) close(ignoreEOF bool) (*ResObjectGet, error) { if x.ctxCall.err != nil { if !errors.Is(x.ctxCall.err, io.EOF) { return nil, x.ctxCall.err - } else if x.remainingPayloadLen > 0 { - return nil, io.ErrUnexpectedEOF } else if !ignoreEOF { + if x.remainingPayloadLen > 0 { + return nil, io.ErrUnexpectedEOF + } + return nil, io.EOF } } @@ -663,9 +665,11 @@ func (x *ObjectRangeReader) close(ignoreEOF bool) (*ResObjectRange, error) { if x.ctxCall.err != nil { if !errors.Is(x.ctxCall.err, io.EOF) { return nil, x.ctxCall.err - } else if x.remainingPayloadLen > 0 { - return nil, io.ErrUnexpectedEOF } else if !ignoreEOF { + if x.remainingPayloadLen > 0 { + return nil, io.ErrUnexpectedEOF + } + return nil, io.EOF } }