gunli commented on PR #1249:
URL: 
https://github.com/apache/pulsar-client-go/pull/1249#issuecomment-2238611023

   Hi @nodece , 
   
   I think calling `p.internalClose(cp)` is not a good idea to fix this bug, 
'cause it breaks the thread/goroutine model of the SDK(the CSP model: DO NOT 
COMMUNICATE BY SHARING MEMORY; INSTEAD, SHARE MEMORY BY COMMUNICATING.). The 
purpose of the cmd channel is to isolate different goroutines, but now we just 
bypass it.
   
   The root cause of this bug is that the event loop is stuck in an infinite 
loop in reconnectToBroker(), I think infinite loop in a case of select{case...} 
is not a good design, we can run the infinite loop in a seperate goroutine, 
like this:
   ```go
   case connectionClosed := <-p.connectClosedCh:
                        p.log.Info("runEventsLoop will reconnect in producer")
                        // Start a new goroutine for reconnecting to broker
                        go p.reconnectToBroker(connectionClosed)
   ```
   
   when the producer is closed, it will quit at:
   ```go
   if p.getProducerState() != producerReady {
                        // Producer is already closing
                        p.log.Info("producer state not ready, exit reconnect")
                        return
                }
   ```


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

Reply via email to