Skip to content

Commit

Permalink
Simplify Distributor.push (#4240)
Browse files Browse the repository at this point in the history
Instead of creating another goroutine to wait for the background
`sendSamples()` to finish, give the channels it is sending on a buffer
so that they can send without a listener.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
  • Loading branch information
bboreham authored Aug 31, 2021
1 parent 6f78ffe commit 13a3df8
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions pkg/distributor/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ func (d *Distributor) Push(ctx context.Context, req *logproto.PushRequest) (*log
}

tracker := pushTracker{
done: make(chan struct{}),
err: make(chan error),
done: make(chan struct{}, 1), // buffer avoids blocking if caller terminates - sendSamples() only sends once on each
err: make(chan error, 1),
}
tracker.samplesPending.Store(int32(len(streams)))
for ingester, samples := range samplesByIngester {
Expand All @@ -300,14 +300,6 @@ func (d *Distributor) Push(ctx context.Context, req *logproto.PushRequest) (*log
case <-tracker.done:
return &logproto.PushResponse{}, validationErr
case <-ctx.Done():
go func() {
select {
case <-tracker.err:
return
case <-tracker.done:
return
}
}()
return nil, ctx.Err()
}
}
Expand Down

0 comments on commit 13a3df8

Please sign in to comment.