From 993c53dfdfd02d4a0b5732990c2e2b4708c964fa Mon Sep 17 00:00:00 2001 From: Bilal Akhtar Date: Sat, 17 Jun 2023 18:25:17 -0400 Subject: [PATCH] storage: Handle EOF correctly in externalStorageReader Previously, if we hit the end of file in externalSTorageWrapper's ReadAt(), even if we were passed a buffer that ended right at EOF, we'd return the EOF error even though we read the file's footer successfully. This deviated from behaviour of other objstorage.Readable implementations and from the behaviour expected by Pebble, and resulted in `unable to read footer (invalid table): EOF` errors in testing. Epic: none Release note: None --- pkg/storage/shared_storage.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/storage/shared_storage.go b/pkg/storage/shared_storage.go index 0bd18b8b23f3..061741fc01a5 100644 --- a/pkg/storage/shared_storage.go +++ b/pkg/storage/shared_storage.go @@ -47,7 +47,10 @@ func (r *externalStorageReader) ReadAt(ctx context.Context, p []byte, offset int defer reader.Close(ctx) for n := 0; n < len(p); { nn, err := reader.Read(ctx, p[n:]) - if err != nil { + // The io.Reader interface allows for io.EOF to be returned even if we just + // successfully filled the buffer p and hit the end of file at the same + // time. Treat that case as a successful read. + if err != nil && !(errors.Is(err, io.EOF) && len(p) == nn+n) { return err } n += nn