Skip to content

Commit

Permalink
fix(downstreamer leak): Use buffered channel to prevent goroutine leak
Browse files Browse the repository at this point in the history
  • Loading branch information
joanmp-ndtx committed Aug 5, 2024
1 parent bdfc86b commit c58f971
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/querier/queryrange/downstreamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (in instance) For(
ctx, cancel := context.WithCancel(ctx)
defer cancel()

ch := make(chan logql.Resp)
ch := make(chan logql.Resp, len(queries)+1)

// ForEachJob blocks until all are done. However, we want to process the
// results as they come in. That's why we start everything in another
Expand Down
6 changes: 6 additions & 0 deletions pkg/querier/queryrange/downstreamer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/atomic"
"go.uber.org/goleak"

"github.com/grafana/loki/v3/pkg/logproto"
"github.com/grafana/loki/v3/pkg/logql"
Expand Down Expand Up @@ -221,6 +222,11 @@ func ensureParallelism(t *testing.T, in *instance, n int) {
}

func TestInstanceFor(t *testing.T) {
// Verify that no leaks exists after the test execution
defer goleak.VerifyNone(t,
goleak.IgnoreCurrent(),
)

mkIn := func() *instance {
return DownstreamHandler{
limits: fakeLimits{},
Expand Down

0 comments on commit c58f971

Please sign in to comment.