Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
105118: storage: Handle EOF correctly in externalStorageReader r=RaduBerinde a=itsbilal

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

Co-authored-by: Bilal Akhtar <[email protected]>
  • Loading branch information
craig[bot] and itsbilal committed Jun 19, 2023
2 parents ba2e9ef + 993c53d commit 126b677
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/storage/shared_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 126b677

Please sign in to comment.