Skip to content

Fix root cause of nil return in queryWithRetry and labelsWithRetry#7375

Open
friedrichg wants to merge 1 commit intomasterfrom
fix-retry-root-cause
Open

Fix root cause of nil return in queryWithRetry and labelsWithRetry#7375
friedrichg wants to merge 1 commit intomasterfrom
fix-retry-root-cause

Conversation

@friedrichg
Copy link
Member

Summary

  • Propagate ctx.Err() from queryWithRetry and labelsWithRetry when the backoff loop exits without executing (e.g. context cancelled before the first attempt), preventing (nil, nil) returns
  • Remove the caller-side nil guard in streamingSelect added by Fix nil when ingesterQueryMaxAttempts > 1 #7369, since the root cause is now fixed at the source
  • Align labelsWithRetry early-return check to use <= 1 consistently with queryWithRetry

Context

PR #7369 fixed the immediate panic in streamingSelect by guarding against nil results at the call site. However the root cause — both retry functions returning (nil, nil) — was still present, leaving labelsWithRetry callers (LabelNames, LabelValues) silently returning empty results with nil error on cancelled context.

Test plan

  • Updated TestDistributorQuerier_Select_CancelledContext to assert context.Canceled error (not just no-panic)
  • Added TestDistributorQuerier_Labels_CancelledContext covering LabelNames and LabelValues with cancelled context and ingesterQueryMaxAttempts > 1
  • All existing retry tests pass

When ingesterQueryMaxAttempts > 1 and the context is cancelled before
the backoff loop starts, retries.Ongoing() returns false immediately
and the loop never executes, causing both retry functions to return
(nil, nil). This propagates ctx.Err() from the retry functions
themselves so all callers are protected, and removes the caller-side
nil guard added in #7369. Also aligns the early-return check in
labelsWithRetry to use <= 1 consistently with queryWithRetry.

Signed-off-by: Friedrich Gonzalez <1517449+friedrichg@users.noreply.github.com>
@friedrichg friedrichg force-pushed the fix-retry-root-cause branch from be6821e to a1ed0ca Compare March 25, 2026 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant