You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "crossoverJie (via GitHub)" <gi...@apache.org> on 2024/03/13 12:47:14 UTC

[PR] [fix] Reconnection logic and Backoff policy doesn't work correctly [pulsar-client-go]

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

   
   Fixes #1187
   
   
   ### Modifications
   
   - Move `backoff.go` to the `backoff` directory (because there are circular dependencies, they are not moved to the pulsar directory.)
   - Create a new method for `BackOffPolicy` interface `IsMaxBackoffReached(delayReconnectTime, totalDelayReconnectTime time.Duration) bool`
   
   
   
   This is a **breaking change** that modifies the package name and interface name.
   
   Package: `internal`->`backoff`
   Interface name: `BackoffPolicy`-> `Policy`
   
   
   ### Verifying this change
   
   - [x] Make sure that the change passes the CI checks.
   
   
   ### 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: (yes)
     - The schema: (no)
     - The default values of configurations: (no)
     - The wire protocol: (no)
   
   ### Documentation
   
     - Does this pull request introduce a new feature? (no)
     - If yes, how is the feature documented? (GoDocs)
     - If a feature is not applicable for documentation, explain why?
     - If a feature is not documented yet in this PR, please create a followup issue for adding the documentation
   


-- 
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] [fix] Reconnection logic and Backoff policy doesn't work correctly [pulsar-client-go]

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


##########
pulsar/backoff/backoff.go:
##########
@@ -38,6 +45,13 @@ type DefaultBackoff struct {
 	backoff time.Duration
 }
 
+func NewDefaultBackoff() Policy {
+	return &DefaultBackoff{}
+}
+func NewDefaultBackoffWithBackOff(backoff time.Duration) Policy {
+	return &DefaultBackoff{backoff: backoff}

Review Comment:
   ```suggestion
   	return &DefaultBackoff{backoff: backoff / 2}
   ```
   
   I think we should treat this as the initial backoff time, right? 
   If it's, then we need to first divide the backoff by 2. Because each time Next is called, the backoff is doubled first.
   



##########
pulsar/backoff/backoff.go:
##########
@@ -38,6 +45,13 @@ type DefaultBackoff struct {
 	backoff time.Duration
 }
 
+func NewDefaultBackoff() Policy {
+	return &DefaultBackoff{}
+}
+func NewDefaultBackoffWithBackOff(backoff time.Duration) Policy {

Review Comment:
   ```suggestion
   func NewDefaultBackoffWithInitialBackOff(backoff time.Duration) Policy {
   ```
   
   Seems this name would be better?



-- 
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] [fix] Reconnection logic and Backoff policy doesn't work correctly [pulsar-client-go]

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


##########
pulsar/producer_partition.go:
##########
@@ -448,17 +460,17 @@ func (p *partitionProducer) getOrCreateSchema(schemaInfo *SchemaInfo) (schemaVer
 }
 
 func (p *partitionProducer) reconnectToBroker(connectionClosed *connectionClosed) {
-	var maxRetry int
+	var (
+		maxRetry                                    int
+		delayReconnectTime, totalDelayReconnectTime time.Duration

Review Comment:
   ```suggestion
   ```



-- 
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] [fix] Reconnection logic and Backoff policy doesn't work correctly [pulsar-client-go]

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


-- 
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] [fix] Reconnection logic and Backoff policy doesn't work correctly [pulsar-client-go]

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


##########
pulsar/dlq_router.go:
##########
@@ -155,7 +156,7 @@ func (r *dlqRouter) getProducer(schema Schema) Producer {
 	}
 
 	// Retry to create producer indefinitely
-	backoff := &internal.DefaultBackoff{}
+	bo := &backoff.DefaultBackoff{}

Review Comment:
   Done.



-- 
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] [fix] Reconnection logic and Backoff policy doesn't work correctly [pulsar-client-go]

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


##########
pulsar/producer_test.go:
##########
@@ -1273,11 +1275,13 @@ func TestProducerWithBackoffPolicy(t *testing.T) {
 
 	topicName := newTopicName()
 
-	backoff := newTestBackoffPolicy(1*time.Second, 4*time.Second)
+	bo := newTestBackoffPolicy(1*time.Second, 4*time.Second)
 	_producer, err := client.CreateProducer(ProducerOptions{
-		Topic:         topicName,
-		SendTimeout:   2 * time.Second,
-		BackoffPolicy: backoff,
+		Topic:       topicName,
+		SendTimeout: 2 * time.Second,
+		BackOffPolicyFunc: func() backoff.Policy {
+			return bo

Review Comment:
   ```suggestion
   			return newTestBackoffPolicy(1*time.Second, 4*time.Second)
   ```



-- 
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] [fix] Reconnection logic and Backoff policy doesn't work correctly [pulsar-client-go]

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


##########
pulsar/backoff/backoff.go:
##########
@@ -15,7 +15,7 @@
 // specific language governing permissions and limitations
 // under the License.
 
-package internal
+package backoff

Review Comment:
   This will lead to a circular dependency.
   
   https://github.com/apache/pulsar-client-go/blob/master/pulsar/internal/http_client.go#L151



##########
pulsar/backoff/backoff.go:
##########
@@ -26,10 +26,14 @@ func init() {
 	rand.Seed(time.Now().UnixNano())
 }
 
-// BackoffPolicy parameterize the following options in the reconnection logic to
+// Policy parameterize the following options in the reconnection logic to
 // allow users to customize the reconnection logic (minBackoff, maxBackoff and jitterPercentage)
-type BackoffPolicy interface {
+type Policy interface {
+	// Next returns the delay to wait before next retry
 	Next() time.Duration
+
+	// IsMaxBackoffReached evaluates if the max number of retries is reached
+	IsMaxBackoffReached(delayReconnectTime, totalDelayReconnectTime time.Duration) bool

Review Comment:
   Done.



-- 
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] [fix] Reconnection logic and Backoff policy doesn't work correctly [pulsar-client-go]

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

   The code conflicts have been resolved, but this PR involves changes to the public API. Do you recommend releasing it in version v0.13.0?


-- 
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] [fix] Reconnection logic and Backoff policy doesn't work correctly [pulsar-client-go]

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


##########
pulsar/producer_partition.go:
##########
@@ -448,17 +460,17 @@ func (p *partitionProducer) getOrCreateSchema(schemaInfo *SchemaInfo) (schemaVer
 }
 
 func (p *partitionProducer) reconnectToBroker(connectionClosed *connectionClosed) {
-	var maxRetry int
+	var (
+		maxRetry                                    int
+		delayReconnectTime, totalDelayReconnectTime time.Duration

Review Comment:
   ```suggestion
   		delayReconnectTime time.Duration
   ```



-- 
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] [fix] Reconnection logic and Backoff policy doesn't work correctly [pulsar-client-go]

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

   > This is a breaking change that modifies the package name and interface name.
   
   A breaking change that we add new method to the `Backoff` interface, not change package name.
   
   In the user project, the user cannot import the `internal` package of the pulsar library, this is a limitation, please check https://go.dev/doc/modules/layout


-- 
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] [fix] Reconnection logic and Backoff policy doesn't work correctly [pulsar-client-go]

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


##########
pulsar/dlq_router.go:
##########
@@ -155,7 +156,7 @@ func (r *dlqRouter) getProducer(schema Schema) Producer {
 	}
 
 	// Retry to create producer indefinitely
-	backoff := &internal.DefaultBackoff{}
+	bo := &backoff.DefaultBackoff{}

Review Comment:
   😅I missed this. It's already fixed.



-- 
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] [fix] Reconnection logic and Backoff policy doesn't work correctly [pulsar-client-go]

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

   Any updates?


-- 
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] [fix] Reconnection logic and Backoff policy doesn't work correctly [pulsar-client-go]

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


##########
pulsar/producer_test.go:
##########
@@ -1273,11 +1275,13 @@ func TestProducerWithBackoffPolicy(t *testing.T) {
 
 	topicName := newTopicName()
 
-	backoff := newTestBackoffPolicy(1*time.Second, 4*time.Second)
+	bo := newTestBackoffPolicy(1*time.Second, 4*time.Second)
 	_producer, err := client.CreateProducer(ProducerOptions{
-		Topic:         topicName,
-		SendTimeout:   2 * time.Second,
-		BackoffPolicy: backoff,
+		Topic:       topicName,
+		SendTimeout: 2 * time.Second,
+		BackOffPolicyFunc: func() backoff.Policy {
+			return bo

Review Comment:
   ```suggestion
   			return newTestBackoffPolicy(1*time.Second, 4*time.Second)
   ```



-- 
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] [fix] Reconnection logic and Backoff policy doesn't work correctly [pulsar-client-go]

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

   > Perhaps we could consider including this change in the 1.0 version.
   
   Yes, I agree with you.


-- 
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] [fix] Reconnection logic and Backoff policy doesn't work correctly [pulsar-client-go]

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


##########
pulsar/backoff/backoff.go:
##########
@@ -15,7 +15,7 @@
 // specific language governing permissions and limitations
 // under the License.
 
-package internal
+package backoff

Review Comment:
   Could you move this pack to the `pulsar` directory and keep `BackoffPolicy`?
   



-- 
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] [fix] Reconnection logic and Backoff policy doesn't work correctly [pulsar-client-go]

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


##########
pulsar/consumer_partition.go:
##########
@@ -1673,11 +1680,8 @@ func (pc *partitionConsumer) reconnectToBroker() {
 			return
 		}
 
-		if pc.options.backoffPolicy == nil {
-			delayReconnectTime = defaultBackoff.Next()
-		} else {
-			delayReconnectTime = pc.options.backoffPolicy.Next()
-		}
+		delayReconnectTime = bo.Next()
+		totalDelayReconnectTime += delayReconnectTime

Review Comment:
   After a successful reconnection at line 1699, the function will exit, and the `delayReconnectTime` variable will be initialized during the next reconnection. 
   
   Therefore, there is no need to reset `delayReconnectTime` here.



-- 
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] [fix] Reconnection logic and Backoff policy doesn't work correctly [pulsar-client-go]

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

   > Package: `internal`->`backoff`
   > Interface name: `BackoffPolicy`-> `Policy`
   
   Update:
   
   `BackoffPolicy internal.BackoffPolicy` -> `BackOffPolicyFunc func() backoff.Policy`:
   
   1. Because the Policy is concurrently called in the consumer, it has been modified to obtain a `policy` object each time using the `backoffPolicyFunc` function.
   
   https://github.com/apache/pulsar-client-go/blob/1152cfc2e3c2024117ecff93a46d90e7eab0fa15/pulsar/consumer_partition.go#L1709-L1712
   
   
   https://github.com/apache/pulsar-client-go/blob/1152cfc2e3c2024117ecff93a46d90e7eab0fa15/pulsar/consumer_partition.go#L607-L609
   
   
   2. A new `Reset` function has been added to the Policy interface, which will be called after a successful reconnection. If a user's custom Policy requires the reuse of the same object, the data can be reset within this `Reset` function.
   
   
   


-- 
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] [fix] Reconnection logic and Backoff policy doesn't work correctly [pulsar-client-go]

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


##########
pulsar/dlq_router.go:
##########
@@ -155,7 +156,7 @@ func (r *dlqRouter) getProducer(schema Schema) Producer {
 	}
 
 	// Retry to create producer indefinitely
-	backoff := &internal.DefaultBackoff{}
+	bo := &backoff.DefaultBackoff{}

Review Comment:
   DefaultBackoff will still be used?
   
   



-- 
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] [fix] Reconnection logic and Backoff policy doesn't work correctly [pulsar-client-go]

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


##########
pulsar/dlq_router.go:
##########
@@ -155,7 +156,7 @@ func (r *dlqRouter) getProducer(schema Schema) Producer {
 	}
 
 	// Retry to create producer indefinitely
-	backoff := &internal.DefaultBackoff{}
+	bo := &backoff.DefaultBackoff{}

Review Comment:
   Could you pass the backoff to the `dlqRouter`?
   
   



##########
pulsar/consumer_partition.go:
##########
@@ -581,11 +583,11 @@ func (pc *partitionConsumer) getLastMessageID() (*trackingMessageID, error) {
 		return nil, errors.New("failed to getLastMessageID for the closing or closed consumer")
 	}
 	remainTime := pc.client.operationTimeout
-	var backoff internal.BackoffPolicy
+	var bo backoff.Policy
 	if pc.options.backoffPolicy != nil {
-		backoff = pc.options.backoffPolicy
+		bo = pc.options.backoffPolicy
 	} else {
-		backoff = &internal.DefaultBackoff{}
+		bo = &backoff.DefaultBackoff{}

Review Comment:
   ```suggestion
   		bo = NewDefaultBackoff()
   ```



##########
pulsar/producer_partition.go:
##########
@@ -448,17 +450,22 @@ func (p *partitionProducer) getOrCreateSchema(schemaInfo *SchemaInfo) (schemaVer
 }
 
 func (p *partitionProducer) reconnectToBroker(connectionClosed *connectionClosed) {
-	var maxRetry int
+	var (
+		maxRetry                                    int
+		delayReconnectTime, totalDelayReconnectTime time.Duration
+	)
 	if p.options.MaxReconnectToBroker == nil {
 		maxRetry = -1
 	} else {
 		maxRetry = int(*p.options.MaxReconnectToBroker)
 	}
 
-	var (
-		delayReconnectTime time.Duration
-		defaultBackoff     = internal.DefaultBackoff{}
-	)
+	var bo backoff.Policy
+	if p.options.BackoffPolicy != nil {
+		bo = p.options.BackoffPolicy
+	} else {
+		bo = &backoff.DefaultBackoff{}

Review Comment:
   ```suggestion
   		bo = NewDefaultBackoff()
   ```



##########
pulsar/backoff/backoff.go:
##########
@@ -26,10 +26,14 @@ func init() {
 	rand.Seed(time.Now().UnixNano())
 }
 
-// BackoffPolicy parameterize the following options in the reconnection logic to
+// Policy parameterize the following options in the reconnection logic to
 // allow users to customize the reconnection logic (minBackoff, maxBackoff and jitterPercentage)
-type BackoffPolicy interface {
+type Policy interface {
+	// Next returns the delay to wait before next retry
 	Next() time.Duration
+
+	// IsMaxBackoffReached evaluates if the max number of retries is reached
+	IsMaxBackoffReached(delayReconnectTime, totalDelayReconnectTime time.Duration) bool

Review Comment:
   If you agree with this idea, you can move the backoff object to the global scope from the local scope, which can reduce the allocation of objects.



##########
pulsar/backoff/backoff.go:
##########
@@ -26,10 +26,14 @@ func init() {
 	rand.Seed(time.Now().UnixNano())
 }
 
-// BackoffPolicy parameterize the following options in the reconnection logic to
+// Policy parameterize the following options in the reconnection logic to
 // allow users to customize the reconnection logic (minBackoff, maxBackoff and jitterPercentage)
-type BackoffPolicy interface {
+type Policy interface {
+	// Next returns the delay to wait before next retry
 	Next() time.Duration
+
+	// IsMaxBackoffReached evaluates if the max number of retries is reached
+	IsMaxBackoffReached(delayReconnectTime, totalDelayReconnectTime time.Duration) bool

Review Comment:
   `delayReconnectTime` and `totalDelayReconnectTime` are unnecessary, we can record this time in the backoff. 
   
   Usually, we need to reset this backoff when some logic works fine, could you add the `Reset()` to this interface.



##########
pulsar/backoff/backoff.go:
##########
@@ -15,7 +15,7 @@
 // specific language governing permissions and limitations
 // under the License.
 
-package internal
+package backoff

Review Comment:
   Could you move this pack to the `pulsar` directory and keep `BackoffPolicy`?
   



##########
pulsar/consumer_partition.go:
##########
@@ -1680,18 +1682,23 @@ func (pc *partitionConsumer) internalClose(req *closeRequest) {
 }
 
 func (pc *partitionConsumer) reconnectToBroker(connectionClosed *connectionClosed) {
-	var maxRetry int
+	var (
+		maxRetry                                    int
+		delayReconnectTime, totalDelayReconnectTime time.Duration
+	)
 
 	if pc.options.maxReconnectToBroker == nil {
 		maxRetry = -1
 	} else {
 		maxRetry = int(*pc.options.maxReconnectToBroker)
 	}
 
-	var (
-		delayReconnectTime time.Duration
-		defaultBackoff     = internal.DefaultBackoff{}
-	)
+	var bo backoff.Policy
+	if pc.options.backoffPolicy != nil {
+		bo = pc.options.backoffPolicy
+	} else {
+		bo = &backoff.DefaultBackoff{}

Review Comment:
   ```suggestion
   		bo = NewDefaultBackoff()
   ```



-- 
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] [fix] Reconnection logic and Backoff policy doesn't work correctly [pulsar-client-go]

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


##########
pulsar/consumer_partition.go:
##########
@@ -1673,11 +1680,8 @@ func (pc *partitionConsumer) reconnectToBroker() {
 			return
 		}
 
-		if pc.options.backoffPolicy == nil {
-			delayReconnectTime = defaultBackoff.Next()
-		} else {
-			delayReconnectTime = pc.options.backoffPolicy.Next()
-		}
+		delayReconnectTime = bo.Next()
+		totalDelayReconnectTime += delayReconnectTime

Review Comment:
   We also need to reset the `delayReconnectTime` once connected after several retries in 1692.



-- 
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] [fix] Reconnection logic and Backoff policy doesn't work correctly [pulsar-client-go]

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

   @RobertIndie PTAL


-- 
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] [fix] Reconnection logic and Backoff policy doesn't work correctly [pulsar-client-go]

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


##########
pulsar/consumer_partition.go:
##########
@@ -1673,11 +1680,8 @@ func (pc *partitionConsumer) reconnectToBroker() {
 			return
 		}
 
-		if pc.options.backoffPolicy == nil {
-			delayReconnectTime = defaultBackoff.Next()
-		} else {
-			delayReconnectTime = pc.options.backoffPolicy.Next()
-		}
+		delayReconnectTime = bo.Next()
+		totalDelayReconnectTime += delayReconnectTime

Review Comment:
   We also need to reset the `delayReconnectTime` once connected after several retries in 1699.



-- 
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] [fix] Reconnection logic and Backoff policy doesn't work correctly [pulsar-client-go]

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


##########
pulsar/producer_partition.go:
##########
@@ -473,11 +485,10 @@ func (p *partitionProducer) reconnectToBroker(connectionClosed *connectionClosed
 			delayReconnectTime = 0
 			assignedBrokerURL = connectionClosed.assignedBrokerURL
 			connectionClosed = nil // Only attempt once
-		} else if p.options.BackoffPolicy == nil {
-			delayReconnectTime = defaultBackoff.Next()
 		} else {
-			delayReconnectTime = p.options.BackoffPolicy.Next()
+			delayReconnectTime = bo.Next()
 		}
+		totalDelayReconnectTime += delayReconnectTime

Review Comment:
   ```suggestion
   ```



-- 
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] [fix] Reconnection logic and Backoff policy doesn't work correctly [pulsar-client-go]

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


##########
pulsar/producer_partition.go:
##########
@@ -448,17 +460,17 @@ func (p *partitionProducer) getOrCreateSchema(schemaInfo *SchemaInfo) (schemaVer
 }
 
 func (p *partitionProducer) reconnectToBroker(connectionClosed *connectionClosed) {
-	var maxRetry int
+	var (
+		maxRetry                                    int
+		delayReconnectTime, totalDelayReconnectTime time.Duration

Review Comment:
   ```suggestion
   ```



-- 
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] [fix] Reconnection logic and Backoff policy doesn't work correctly [pulsar-client-go]

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


##########
pulsar/backoff/backoff.go:
##########
@@ -15,7 +15,7 @@
 // specific language governing permissions and limitations
 // under the License.
 
-package internal
+package backoff

Review Comment:
   Could you move this pack to the `pulsar` directory and keep `BackoffPolicy`?
   



-- 
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