You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "Gilthoniel (via GitHub)" <gi...@apache.org> on 2025/06/18 09:21:54 UTC

[PR] [Issue 1384][consumer] Fix the default nack backoff policy [pulsar-client-go]

Gilthoniel opened a new pull request, #1385:
URL: https://github.com/apache/pulsar-client-go/pull/1385

   <!--
   ### Contribution Checklist
     
     - Name the pull request in the form "[Issue XYZ][component] Title of the pull request", where *XYZ* should be replaced by the actual issue number.
       Skip *Issue XYZ* if there is no associated github issue for this pull request.
       Skip *component* if you are unsure about which is the best component. E.g. `[docs] Fix typo in produce method`.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   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
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Issue 1384][consumer] Fix the default nack backoff policy [pulsar-client-go]

Posted by "Gilthoniel (via GitHub)" <gi...@apache.org>.
Gilthoniel commented on code in PR #1385:
URL: https://github.com/apache/pulsar-client-go/pull/1385#discussion_r2154129351


##########
pulsar/negative_backoff_policy.go:
##########
@@ -41,9 +41,11 @@ func (nbp *defaultNackBackoffPolicy) Next(redeliveryCount uint32) time.Duration
 	minNackTime := 1 * time.Second  // 1sec
 	maxNackTime := 10 * time.Minute // 10min
 
-	if redeliveryCount < 0 {

Review Comment:
   Please note that it cannot be below zero as the type is `uint32`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Issue 1384][consumer] Fix the default nack backoff policy [pulsar-client-go]

Posted by "crossoverJie (via GitHub)" <gi...@apache.org>.
crossoverJie merged PR #1385:
URL: https://github.com/apache/pulsar-client-go/pull/1385


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Issue 1384][consumer] Fix the default nack backoff policy [pulsar-client-go]

Posted by "Gilthoniel (via GitHub)" <gi...@apache.org>.
Gilthoniel commented on PR #1385:
URL: https://github.com/apache/pulsar-client-go/pull/1385#issuecomment-3051287265

   Rebase done to fix the previous issue on master.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Issue 1384][consumer] Fix the default nack backoff policy [pulsar-client-go]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #1385:
URL: https://github.com/apache/pulsar-client-go/pull/1385#discussion_r2194235740


##########
pulsar/negative_backoff_policy.go:
##########
@@ -41,9 +41,11 @@ func (nbp *defaultNackBackoffPolicy) Next(redeliveryCount uint32) time.Duration
 	minNackTime := 1 * time.Second  // 1sec
 	maxNackTime := 10 * time.Minute // 10min
 
-	if redeliveryCount < 0 {
-		return minNackTime
+	backoff := float64(minNackTime << redeliveryCount)
+	if backoff == 0 {
+		// Overflow so we assign the maximum value of the backoff.
+		backoff = float64(maxNackTime)
 	}
 
-	return time.Duration(math.Min(math.Abs(float64(minNackTime<<redeliveryCount)), float64(maxNackTime)))
+	return time.Duration(math.Min(math.Abs(backoff), float64(maxNackTime)))

Review Comment:
   [nitpick] The call to `math.Abs` is redundant because `backoff` is always non-negative. You can simplify to `math.Min(backoff, float64(maxNackTime))`.
   ```suggestion
   	return time.Duration(math.Min(backoff, float64(maxNackTime)))
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org