Skip to content

notify: prevent Retry-After duration overflow - #5751

Closed
shubhamcommits wants to merge 2 commits into
prometheus:mainfrom
shubhamcommits:fix/retry-after-duration-overflow
Closed

shubhamcommits wants to merge 2 commits into
prometheus:mainfrom
shubhamcommits:fix/retry-after-duration-overflow

Conversation

@shubhamcommits

@shubhamcommits shubhamcommits commented Nov 17, 2026 •

Copy link
Copy Markdown

Large integer Retry-After values can overflow when converted from seconds to time.Duration. A positive delay can become zero, while a malformed negative value can become a large positive wait.

Parse seconds with an explicit 64-bit width, reject negatives before multiplication, and saturate valid positive delays at the maximum representable duration. Validate the entire decimal value after a parsing overflow so malformed suffixes still fall back to zero. Ordinary integer and HTTP-date behavior is preserved.

This addresses the representational overflow discussed in #5389; the bound is time.Duration's limit rather than a retry-policy cutoff.

Pull Request Checklist

  • Related discussion: feat(notify): generic ParseRetryAfter for parsing Headers #5389.
  • Is this a new Receiver integration? No.
    • I have already tried to use the Webhook Receiver Integration and third-party integrations before adding this new Receiver Integration
  • Is this a bugfix? Yes.
    • I have added tests that reproduce the bug and pass with this fix
  • Is this a new feature? No.
    • I have added tests that test the new feature's functionality
  • Does this change affect performance? No intended performance change.
    • I have provided benchmarks comparison
    • I have added new benchmarks if required or requested
  • Is this a breaking change? No.
    • My changes do not break existing cluster messages
    • My changes do not break the existing API
  • The exported helper's documentation describes saturation
  • I have signed-off my commits
  • I will follow best practices for contributing to this project

Validation:

  • Seven boundary regressions fail against the unchanged helper. The fixed parser passes all 23 table cases, including malformed oversized integers and HTTP dates.
  • All notifier packages pass on Go 1.26.5; race checks pass for the shared notifier package, Slack and Webex.
  • Independent arbitrary-precision/date and lexical-reference harnesses pass 24,210 and 234,972 cases respectively, including threshold neighbors, malformed byte sequences and very long inputs.
  • The actual notifier tests cross-compile for linux/386 on Go 1.26.5; 386 execution was not performed.
  • make common-format and make lint pass with pinned golangci-lint v2.14.0; Elm/Mantine builds, all 43 UI tests and UI lint pass.
  • Full Linux go test ./... with built assets and versioned server/CLI binaries has one failure, TestAlertGetReturnsCurrentAlertStatus. The exact unchanged baseline 373edcb5a2dbdf6a6f7c08de3078cf19f996b47d reproduces that same failure. All other packages pass.

Which user-facing changes does this PR introduce?

[BUGFIX] Notifications: Prevent large Retry-After values from wrapping into incorrect retry delays.

Signed-off-by: Shubham Singh <development.shubhamsingh@gmail.com>
@shubhamcommits
shubhamcommits requested a review from a team as a code owner November 17, 2026 13:09
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

Commits

Reviewing files that changed from the base of the PR and between f67035f and 0b5b5ed.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

ParseRetryAfter now parses integer delays as signed 64-bit seconds, returns zero for negative values, and caps delays above the time.Duration limit. Tests add coverage for large values and malformed overflow inputs.

Changes: Retry-After parsing

Layer / File(s) Summary
Integer delay handling
notify/util.go, notify/util_test.go
ParseRetryAfter uses 64-bit integer parsing, returns zero for negative values, and caps oversized delays at the duration maximum. Tests cover values beyond 32-bit and integer limits, plus overflow strings with trailing text.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: Minimal · previous review f6703

This change prevents very large Retry-After values from wrapping into incorrect retry delays. Ordinary integer and HTTP-date handling is intended to stay the same, and tests cover the boundary cases. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "notify: prevent Retry-After duration overflow" names the main change: the fix for integer Retry-After values that overflow when converted to time.Duration. It follows the area: description …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description explains the overflow problem in ParseRetryAfter, the fix (64-bit parsing, rejecting negatives before multiplication, saturating positive delays, validating the full decimal value afte…
Full details: Title check

Explanation

The title "notify: prevent Retry-After duration overflow" names the main change: the fix for integer Retry-After values that overflow when converted to time.Duration. It follows the area: description form the template asks for and matches the raw summary, the PR objectives, and the release note.

Full details: Description check

Explanation

The description explains the overflow problem in ParseRetryAfter, the fix (64-bit parsing, rejecting negatives before multiplication, saturating positive delays, validating the full decimal value after overflow), and the reference to #5389. It fills in most checklist items and includes a release-notes block. The template's title format and the 'Fixes #' line are not addressed. The 'Which user-facing changes' section is complete. The checklist leaves the performance benchmark item unchecked, which is acceptable because the author states there is no intended performance change. The description is mostly complete.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 373edcb and f67035f.

Files selected for processing: 2

  • notify/util.go
  • notify/util_test.go

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

@jamesconwaydev jamesconwaydev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read against main, and I ran strconv.ParseInt on the overflow inputs. The fix is right, and the digit loop is needed, for the reason the comment gives:

  • "+18446744073709551616x" (past uint64) returns ErrRange with MaxInt64 before ParseUint reaches the x, so without the loop it would saturate instead of falling back to 0.
  • "9223372036854775808seconds" (past int64 but within uint64) comes back as invalid syntax first, so that test case passes through the HTTP-date fallback, not the loop. It's worth knowing if someone later trims the loop as unused for that case.

The saturation boundary checks out: 9223372036 * 1e9 fits in an int64 and 9223372037 * 1e9 doesn't. Both callers (Slack and Webex) pass the result straight to notify.Retry, so the cap on how long a retry may wait stays the question for #5389, as the description says.

One small thing to decide rather than fix: ParseInt accepts a leading +, as Atoi did, so +5 is still 5 s, although RFC 9110's 1*DIGIT makes it malformed like the negative case. Keeping it avoids a behaviour change.

Read and the parse cases run; I didn't run the package tests.

@SoloJacobs SoloJacobs left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, but I don't see the value there. If the server is reporting 292 years of backoff, something is broken already. There is no value in detecting this case (It will really be clamped to the normal backoff). It already was an AI comment back then, which we rejected. Reopening such a PR is questionable.

@shubhamcommits

Copy link
Copy Markdown
Author

Sorry, but I don't see the value there. If the server is reporting 292 years of backoff, something is broken already. There is no value in detecting this case (It will really be clamped to the normal backoff). It already was an AI comment back then, which we rejected. Reopening such a PR is questionable.

@SoloJacobs - Thanks for clarifying and pointing me back to the earlier discussion. One question before I close this: max(backoff, retryAfter) handles nonpositive overflow results, but a wrapped positive value can still extend the wait. Would a smaller change that treats unrepresentable values as invalid and falls back to ordinary backoff be useful, or would you prefer to leave these extreme inputs out of scope?

@SoloJacobs

Copy link
Copy Markdown
Contributor

Let's just leave it. If somebody has a real world use-case in Alertmanager, I am happy to revisit this. Thanks.

@SoloJacobs SoloJacobs closed this Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants