jonyhy96 commented on a change in pull request #360:
URL: https://github.com/apache/pulsar-client-go/pull/360#discussion_r476237458



##########
File path: pulsar/producer_partition.go
##########
@@ -236,8 +236,18 @@ func (p *partitionProducer) ConnectionClosed() {
 }
 
 func (p *partitionProducer) reconnectToBroker() {
-       backoff := internal.Backoff{}
-       for {
+       var (
+               maxRetry int
+               backoff  = internal.Backoff{}
+       )
+
+       if p.options.MaxReconnectToBroker == nil {
+               maxRetry = -1
+       } else {
+               maxRetry = int(*p.options.MaxReconnectToBroker)
+       }

Review comment:
       > The handling for uninitialized maxRetry seems not correct, it may be 
better to extract the retry test into a separate function, e.g `shouldRetry`.
   
   ```go
   func (p *partitionProducer) limitRetry() bool {
    return p.options.MaxReconnectToBroker != nil
   }
   
   func (p *partitionProducer) reconnectToBroker() {
   ...
    var maxRetry = -1
    if p.limitRetry() {
      maxRetry = int(*p.options.MaxReconnectToBroker)  
    }
   ...
   }
   ```
   
   Do you mean something like this?
   




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to