Skip to content

Commit

Permalink
chore: clone the context instead of using background context while pu…
Browse files Browse the repository at this point in the history
…shing logs to ingesters from distributor (#15735)
  • Loading branch information
sandeepsukhani authored Jan 14, 2025
1 parent fa7a6a9 commit 1130542
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions pkg/distributor/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
ring_client "github.com/grafana/dskit/ring/client"
"github.com/grafana/dskit/services"
"github.com/grafana/dskit/tenant"
"github.com/grafana/dskit/user"
lru "github.com/hashicorp/golang-lru/v2"
"github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
Expand Down Expand Up @@ -701,9 +700,9 @@ func (d *Distributor) Push(ctx context.Context, req *logproto.PushRequest) (*log

for ingester, streams := range streamsByIngester {
func(ingester ring.InstanceDesc, samples []*streamTracker) {
// Use a background context to make sure all ingesters get samples even if we return early
localCtx, cancel := context.WithTimeout(context.Background(), d.clientCfg.RemoteTimeout)
localCtx = user.InjectOrgID(localCtx, tenantID)
// Clone the context using WithoutCancel, which is not canceled when parent is canceled.
// This is to make sure all ingesters get samples even if we return early
localCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), d.clientCfg.RemoteTimeout)
if sp := opentracing.SpanFromContext(ctx); sp != nil {
localCtx = opentracing.ContextWithSpan(localCtx, sp)
}
Expand Down

0 comments on commit 1130542

Please sign in to comment.