Skip to content

Commit

Permalink
fix(queryrange): properly handle context cancellation in Downstreamer (
Browse files Browse the repository at this point in the history
  • Loading branch information
cyriltovena authored Feb 26, 2025
1 parent 8976709 commit 5335a21
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions pkg/querier/queryrange/downstreamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,26 @@ func (in instance) For(
}()

var err error
for resp := range ch {
if err != nil {
continue
}
if resp.Err != nil {
err = resp.Err
continue
for {
select {
case <-ctx.Done():
// Return early if the context is canceled
return acc.Result(), ctx.Err()
case resp, ok := <-ch:
if !ok {
// Channel closed, we're done
return acc.Result(), err
}
if err != nil {
continue
}
if resp.Err != nil {
err = resp.Err
continue
}
err = acc.Accumulate(ctx, resp.Res, resp.I)
}
err = acc.Accumulate(ctx, resp.Res, resp.I)
}

return acc.Result(), err
}

// convert to matrix
Expand Down

0 comments on commit 5335a21

Please sign in to comment.