wolfstudy commented on pull request #559:
URL: https://github.com/apache/pulsar-client-go/pull/559#issuecomment-871971746


   Hello @cckellogg , In connection start, We first judge whether the TCP 
connection is established successfully.
   
   ```
   if c.connect(){}
   ```
   
    If the connection is established successfully but the handshake fails, we 
will branch else, but here we just change the connection status to 
connectionClosed without directly closing the TCP connection. 
   
   ```
   else {
        c.metrics.ConnectionsHandshakeErrors.Inc()
        c.changeState(connectionClosed)
   }
   ```
   
   But in the Close function, when the connection is in the `connectionClosed` 
state, it returns directly, and does not perform the TCP close operation
   
   ```
   func (c *connection) Close() {
        c.Lock()
        defer c.Unlock()
   
        c.cond.Broadcast()
   
        if c.getState() == connectionClosed {
                return
        }
   ```
   
   
   So here in the reconnect process, it will cause multiple TCP connections to 
be created locally, resulting in TCP connection resources leakage.
   
   
![image](https://user-images.githubusercontent.com/20965307/124078688-c4f22180-da7a-11eb-8e43-2867d6a74313.png)
   
   Here for the `515` process, only one pulsar Client object is created. In 
theory, only one TCP connection should be established here, but during the 
reconnect process, it was found that multiple TCP connections were created 
locally, and there was a leak of TCP connection resources.


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