jiazhai commented on pull request #366:
URL: https://github.com/apache/pulsar-client-go/pull/366#issuecomment-696759873


   Try to provide a brief summary for the deadlock.
   
   In pulsar/internal/connection.go we have 2 channels, `closeCh` and  
`incomingRequestsCh`, which are init as
   
   ```
   closeCh:            make(chan interface{}),
   incomingRequestsCh: make(chan *request, 10),    < === buffer limited
   ```
   `incomingRequestsCh` is a buffered channel with length 10.
   
   
![image](https://user-images.githubusercontent.com/6348208/93894965-e0791080-fd21-11ea-93ed-716f9ef07c8a.png)
   
![image](https://user-images.githubusercontent.com/6348208/93895012-ee2e9600-fd21-11ea-9301-372ac000eadb.png)
   
   when connection is closed,  method `func (c *connection) Close()` will call 
`func (c *connection) TriggerClose()`, which closed `closeCh` by 
`close(c.closeCh)`,
   
![image](https://user-images.githubusercontent.com/6348208/93895117-10c0af00-fd22-11ea-8b2b-dee3ca3cf232.png)
   
![image](https://user-images.githubusercontent.com/6348208/93895133-14543600-fd22-11ea-96ce-90cb35b09d32.png)
   
   this will cause go routine (in connection.go.run()) exit,  then no one will 
fetch messages in `incomingRequestsCh`. `incomingRequestsCh`, whose buffer 
length is 10,  will be filled with incoming requests by method `func (c 
*connection) SendRequestNoWait(req *pb.BaseCommand)`, 
   
![image](https://user-images.githubusercontent.com/6348208/93895485-744adc80-fd22-11ea-9bb8-8e75725084a0.png)
   
![image](https://user-images.githubusercontent.com/6348208/93895552-888ed980-fd22-11ea-87ad-4c2f67beb20b.png)
   
   Then the 10th request, it will be blocked, 
   
![image](https://user-images.githubusercontent.com/6348208/93895661-a78d6b80-fd22-11ea-9cb7-128c4314491b.png)
   
   As show in above dump thread,  `internalAck` in `runEventsLoop` is blocked, 
then other requests like re-connection will not get handled, and caused  ` 
"consumers" : [ ], <-- NO CONSUMERS HERE`
   
![image](https://user-images.githubusercontent.com/6348208/93895687-b07e3d00-fd22-11ea-86ea-e8dcddcaba75.png)
   
   Backing to `func (c *connection) Close()`, the connection 
`handler.ConnectionClosed()` will hang, because  channel `pc.eventsCh` is 
blocked as ackRequest is waiting.
   
![image](https://user-images.githubusercontent.com/6348208/93895803-ca1f8480-fd22-11ea-8371-152eb40a5cd8.png)
   
![image](https://user-images.githubusercontent.com/6348208/93895822-ce4ba200-fd22-11ea-8231-0a4736169d45.png)
   
   
   
   
   
   


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