Skip to content

Commit

Permalink
Return context.Cause(ctx) as error so we can use custom timeout errors (
Browse files Browse the repository at this point in the history
#10815)

* Return context.Cause(ctx) as error so we can use custom timeout errors

* Add comment
  • Loading branch information
zenador authored Mar 6, 2025
1 parent 04cee96 commit 75ec258
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/frontend/querymiddleware/limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package querymiddleware

import (
"context"
"errors"
"fmt"
"net/http"
"time"
Expand Down Expand Up @@ -250,6 +251,12 @@ func (rt limitedParallelismRoundTripper) RoundTrip(r *http.Request) (*http.Respo
response, err := rt.middleware.Wrap(
HandlerFunc(func(ctx context.Context, r MetricsQueryRequest) (Response, error) {
if err := sem.Acquire(ctx, 1); err != nil {
// Without this change, using WithTimeoutCause has no effect when calling Do on
// limitedParallelismRoundTripper, since that would need to return the cause as error,
// which is the normal behaviour except that semaphore does not do that.
if errors.Is(err, ctx.Err()) {
err = context.Cause(ctx)
}
return nil, fmt.Errorf("could not acquire work: %w", err)
}
defer sem.Release(1)
Expand Down

0 comments on commit 75ec258

Please sign in to comment.