Skip to content

fix(connector): clamp exponential backoff shift to avoid uint32 wraparound - #109

Merged
matthyx merged 1 commit into
kubescape:mainfrom
magic-peach:fix-nack-backoff-shift-overflow
Aug 19, 2026
Merged

matthyx merged 1 commit into
kubescape:mainfrom
magic-peach:fix-nack-backoff-shift-overflow

Conversation

@magic-peach

Copy link
Copy Markdown
Contributor

Noticed this while reading through the DLQ backoff policy - calculateIncrementalDelay's exponential path does uint32(1 << redeliveryCount). Once redeliveryCount reaches 32, that shift wraps a uint32 around to 0, so a message that's been redelivered that many times gets an instant redelivery instead of the configured max delay. That's the opposite of what backoff is for - a message stuck failing for a while ends up getting hammered instead of throttled.

Clamped the shift so it stops growing at the point where it would overflow, same behavior as before for every redelivery count anyone's actually likely to hit, correct behavior past it.

Added a test at redeliveryCount 32 with a max configured - confirmed it returns 0s on the old code and the capped delay now.

…round

calculateIncrementalDelay does uint32(1 << redeliveryCount) for exponential
backoff. Once redeliveryCount hits 32 that shift wraps a uint32 to 0, so a
message that's been redelivered that many times gets an instant redelivery
instead of the configured max delay - worse than no backoff at all.

Clamp the shift amount before applying it.

Signed-off-by: Akanksha Trehun <akankshatrehun@gmail.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Aug 18, 2026

Copy link
Copy Markdown

Important

Review available on request

  • 🔍 Trigger review

Reviews should be triggered manually for repositories with fewer than 10 stars. Select Trigger review above or comment @coderabbitai review to review the latest changes. For a full review, comment @coderabbitai full review.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e8b85d63-1759-49b1-894d-ff1bbdc730ed


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

Comment @coderabbitai help to get the list of available commands.

@matthyx matthyx 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.

Verified the fix: Go's shift operator on uint32 is defined for any shift count (unlike C), so 1 << 32 legitimately wraps to 0 — the bug as described is real and the fix (clamping the shift to 31 once redeliveryCount >= 32) is correct.

Checked the boundary cases:

  • redeliveryCount <= 31: shift is unchanged, so behavior is identical to before (no regression).
  • redeliveryCount >= 32: shift clamps to 31, giving 2^31 (fits safely in uint32, no overflow), which then gets capped by maxRedeliveryDelayMultiplier as before instead of wrapping to 0.

The added test (redeliveryCount: 32) exercises the public Next() path end-to-end and matches this. No blockers — LGTM.

@matthyx matthyx moved this to Waiting on Author in KS PRs tracking Aug 19, 2026
@matthyx
matthyx merged commit b65e2ba into kubescape:main Aug 19, 2026
7 of 11 checks passed
@matthyx matthyx moved this from Waiting on Author to To Archive in KS PRs tracking Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants