Skip to content
This repository has been archived by the owner on Jan 12, 2023. It is now read-only.

Commit

Permalink
defers putting slice back into pool on ingester push to prevent panic…
Browse files Browse the repository at this point in the history
…king Error() calls which reference underlying labels

Signed-off-by: Owen Diehl <ow.diehl@gmail.com>
  • Loading branch information
owen-d committed Jan 17, 2020
1 parent 6a33f49 commit 252a1a8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pkg/ingester/ingester.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ func (i *Ingester) Push(ctx old_ctx.Context, req *client.WriteRequest) (*client.
return i.v2Push(ctx, req)
}

defer client.ReuseSlice(req.Timeseries)

userID, err := user.ExtractOrgID(ctx)
if err != nil {
return nil, fmt.Errorf("no user id")
Expand All @@ -311,7 +313,6 @@ func (i *Ingester) Push(ctx old_ctx.Context, req *client.WriteRequest) (*client.
return nil, wrapWithUser(err, userID)
}
}
client.ReuseSlice(req.Timeseries)

if lastPartialErr != nil {
return &client.WriteResponse{}, lastPartialErr.WrapWithUser(userID).WrappedError()
Expand Down
4 changes: 2 additions & 2 deletions pkg/ingester/ingester_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ func NewV2(cfg Config, clientConfig client.Config, limits *validation.Overrides,
func (i *Ingester) v2Push(ctx old_ctx.Context, req *client.WriteRequest) (*client.WriteResponse, error) {
var lastPartialErr error

defer client.ReuseSlice(req.Timeseries)

userID, err := user.ExtractOrgID(ctx)
if err != nil {
return nil, fmt.Errorf("no user id")
Expand Down Expand Up @@ -157,8 +159,6 @@ func (i *Ingester) v2Push(ctx old_ctx.Context, req *client.WriteRequest) (*clien
i.metrics.ingestedSamples.Add(float64(succeededSamplesCount))
i.metrics.ingestedSamplesFail.Add(float64(failedSamplesCount))

client.ReuseSlice(req.Timeseries)

if lastPartialErr != nil {
return &client.WriteResponse{}, httpgrpc.Errorf(http.StatusBadRequest, wrapWithUser(lastPartialErr, userID).Error())
}
Expand Down

0 comments on commit 252a1a8

Please sign in to comment.