BewareMyPower opened a new pull request, #1500:
URL: https://github.com/apache/pulsar-client-go/pull/1500

   ### Motivation
   
   #1494 introduces a possible deadlock after ensuring the thread safety.
   
   To fix the thread safety issue, every APIs that need to find a specific 
sub-consumer, like `Ack` and `Seek`, will now require locking the parent 
consumer. However, in `internalTopicSubscribeToPartitions`, it will wait all 
sub-consumers' creations are done:
   
   
https://github.com/apache/pulsar-client-go/blob/87ce8f90d0e2df9402133ebc52560638bb09778d/pulsar/consumer_impl.go#L414-L416
   
   
https://github.com/apache/pulsar-client-go/blob/87ce8f90d0e2df9402133ebc52560638bb09778d/pulsar/consumer_impl.go#L428
   
   `range ch` will wait the `err` returned by `newPartitionConsumer` is sent to 
the `ch`.
   
   However, it could be blocked by `grabConn`: 
https://github.com/apache/pulsar-client-go/blob/87ce8f90d0e2df9402133ebc52560638bb09778d/pulsar/consumer_partition.go#L434
   
   this could start a Subscribe RPC in the connection that might receive user's 
Ack or Seek requests.
   
   ### Modifications
   
   - Add 
`TestInternalTopicSubscribeToPartitionsDoesNotBlockExistingPartitionLookup` to 
reproduce the deadlock issue.
   - Adopt the lock-free implementation to manage consumers, the test above 
will pass after test
   - Delay the dispatching logic after adding new sub-consumers to 
`c.consumers`, otherwise, a message could be received from a new sub-consumer 
and acknowledged before that consumer is added to `c.consumers`.
   - Add 
`TestInternalTopicSubscribeToPartitionsPublishesConsumersBeforeDispatchingMessages`
 to verify it works


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