Skip to content

Commit

Permalink
[fix panic] s3: fix object nil point (#6970)
Browse files Browse the repository at this point in the history
**What this PR does / why we need it**:
fix a s3 panic.
```go
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x14fec7b]

goroutine 6271245 [running]:
github.com/grafana/loki/pkg/storage/chunk/client.(*client).getChunk(_, {_, _}, _, {{0xb130cf997b272f99, {0xc05077e6a0, 0x1b}, 0x182d1aefb2d, 0x182d1b47984, 0x9fab6388}, ...})
/loki@v1.6.2-0.20220816085209-65ed7b60fbd4/pkg/storage/chunk/client/object_client.go:171 +0x2fb
```
  • Loading branch information
liguozhong authored Aug 26, 2022
1 parent a12b080 commit e3cd312
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/storage/chunk/client/aws/s3_storage_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ func (a *S3ObjectClient) GetObject(ctx context.Context, objectKey string) (io.Re
if resp.ContentLength != nil {
size = *resp.ContentLength
}
if err == nil {
if err == nil && resp.Body != nil {
return resp.Body, size, nil
}
retries.Wait()
Expand Down
3 changes: 3 additions & 0 deletions pkg/storage/chunk/client/object_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ func (o *client) getChunk(ctx context.Context, decodeContext *chunk.DecodeContex
return chunk.Chunk{}, errors.WithStack(err)
}

if readCloser == nil {
return chunk.Chunk{}, errors.New("object client getChunk fail because object is nil")
}
defer readCloser.Close()

// adds bytes.MinRead to avoid allocations when the size is known.
Expand Down

0 comments on commit e3cd312

Please sign in to comment.