Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Handle EOF when reading from some obj stores #13868

Merged
merged 3 commits into from
Aug 14, 2024

Conversation

benclive
Copy link
Contributor

What this PR does / why we need it:

  • Fixes reading from some storage providers that return an EOF when done instead of a nil error.
  • This is a valid response, we just didn't handle it properly.

@benclive benclive requested a review from a team as a code owner August 13, 2024 09:07
@benclive benclive changed the title Benclive/fix read from gcs fix: Handle EOF when reading from some obj stores Aug 13, 2024
Copy link
Contributor

@grobinson-grafana grobinson-grafana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pkg/errors is no longer recommended since errors was added to stdlib. Otherwise LGTM! 👍

"sort"

"github.com/pkg/errors"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"github.com/pkg/errors"
"errors"

@@ -309,14 +311,14 @@ func readChunkData(ctx context.Context, storage BlockStorage, chunk ChunkData) (
// together.
reader, err := storage.GetObjectRange(ctx, wal.Dir+chunk.id, int64(offset), int64(size))
if err != nil {
return nil, err
return nil, errors.Wrap(err, "could not get range reader for "+chunk.id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return nil, errors.Wrap(err, "could not get range reader for "+chunk.id)
return nil, fmt.Errorf("could not get range reader for %s: %w", chunk.id, err)

}
defer reader.Close()

data := make([]byte, size)
_, err = reader.Read(data)
if err != nil {
return nil, err
if err != nil && err != io.EOF {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if err != nil && err != io.EOF {
if err != nil && !errors.Is(err, io.EOF) {

if err != nil {
return nil, err
if err != nil && err != io.EOF {
return nil, errors.Wrap(err, "could not read socket for "+chunk.id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return nil, errors.Wrap(err, "could not read socket for "+chunk.id)
return nil, fmt.Errorf("could not read socket for %s: %w", chunk.id, err)

@benclive benclive merged commit 98a15e2 into main Aug 14, 2024
62 checks passed
@benclive benclive deleted the benclive/fix-read-from-gcs branch August 14, 2024 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants