BewareMyPower commented on code in PR #1208:
URL: https://github.com/apache/pulsar-client-go/pull/1208#discussion_r1576526236
##########
pulsar/producer_partition.go:
##########
@@ -429,12 +453,22 @@ func (p *partitionProducer) reconnectToBroker() {
return
}
- if p.options.BackoffPolicy == nil {
+ var assignedBrokerURL string
+
+ if connectionClosed != nil && connectionClosed.HasURL() {
+ delayReconnectTime = 0
+ assignedBrokerURL = connectionClosed.assignedBrokerURL
+ connectionClosed = nil // Only attempt once
Review Comment:
How about moving the `assignedBrokerURL` out of the for loop?
```go
assignedBrokerURL = ""
if connectionClosed != nil && connectionClosed.HasURL() {
assignedBrokerURL = connectionClosed.assignedBrokerURL
}
for maxRetry != 0 {
// ...
if p.options.BackoffPolicy == nil {
delayReconnectTime = defaultBackoff.Next()
} else {
delayReconnectTime = p.options.BackoffPolicy.Next()
}
// ...
err := p.grabCnx(assignedBrokerURL)
```
When `connectionClosed` is nil, `assignedBrokerURL` will be an empty string
and `grabCnx(assignedBrokerURL)` will be equivalent with `grabCnx("")`.
The code will look more clear and less code changes are needed.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]