Skip to content

[Issue 1384][consumer] Fix the default nack backoff policy - #1385

Merged
crossoverJie merged 2 commits into
apache:masterfrom
Gilthoniel:bugfix/default-nack-backoff
Jul 10, 2025
Merged

crossoverJie merged 2 commits into
apache:masterfrom
Gilthoniel:bugfix/default-nack-backoff

Conversation

@Gilthoniel

@Gilthoniel Gilthoniel commented Jun 18, 2025 •

Copy link
Copy Markdown
Contributor

Fixes #1384

Motivation

Once the redelivery count is high enough, the backoff time overflows to zero causing immediate redelivery.

Modifications

Check for the overflow to assign the max backoff time in that case.

Verifying this change

  • Make sure that the change passes the CI checks.

This change is already covered by existing tests, such as:

  • Extend TestDefaultNackBackoffPolicy_Next with failing cases added.

Does this pull request potentially affect one of the following parts:

If yes was chosen, please highlight the changes

  • Dependencies (does it add or upgrade a dependency): no
  • The public API: no
  • The schema: no
  • The default values of configurations: no
  • The wire protocol: no

Documentation

  • Does this pull request introduce a new feature? no

Comment thread pulsar/negative_backoff_policy.go Resolved
@Gilthoniel
Gilthoniel force-pushed the bugfix/default-nack-backoff branch from f85b6c8 to 0c1d4ed Compare July 9, 2025 06:22
@Gilthoniel

Copy link
Copy Markdown
Contributor Author

Rebase done to fix the previous issue on master.

Copilot AI 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.

Pull Request Overview

This PR addresses an overflow issue in the default negative-acknowledgement backoff policy by capping the computed backoff to the configured maximum when the shift overflows.

  • Change backoff calculation to detect overflow (resulting in zero) and assign max backoff
  • Remove unreachable negative-count check
  • Extend tests to cover large redelivery counts and overflow scenarios

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
pulsar/negative_backoff_policy.go Detect shift overflow, clamp backoff to maxNackTime
pulsar/negative_backoff_policy_test.go Import math, add overflow test cases
Comments suppressed due to low confidence (3)

pulsar/negative_backoff_policy_test.go:34

  • math.MaxUint8 is not defined in the standard math package, causing a compile error. Use an explicit literal like 255 or define a constant (e.g., const maxUint8 = ^uint8(0)) and cast to uint32.
	assert.Equal(t, 10*time.Minute, defaultNackBackoff.Next(math.MaxUint8))

pulsar/negative_backoff_policy_test.go:35

  • math.MaxUint16 is not defined in the standard math package, causing a compile error. Use an explicit literal like 65535 or define a constant (e.g., const maxUint16 = ^uint16(0)) and cast to uint32.
	assert.Equal(t, 10*time.Minute, defaultNackBackoff.Next(math.MaxUint16))

pulsar/negative_backoff_policy_test.go:36

  • math.MaxUint32 is not defined in the standard math package, causing a compile error. Use ^uint32(0) directly or define a constant for math.MaxUint32 before use.
	assert.Equal(t, 10*time.Minute, defaultNackBackoff.Next(math.MaxUint32))

Comment thread pulsar/negative_backoff_policy.go Resolved
@crossoverJie crossoverJie added this to the v0.16.0 milestone Jul 9, 2025

@crossoverJie crossoverJie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@crossoverJie
crossoverJie merged commit c587b5c into apache:master Jul 10, 2025
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.

[Bug] default nack backoff policy overflows to zero

3 participants