You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/07/19 03:15:24 UTC

[GitHub] [pulsar-client-go] crossoverJie commented on a diff in pull request #808: [Issue 387] fix goroutine leak for closing consumers.

crossoverJie commented on code in PR #808:
URL: https://github.com/apache/pulsar-client-go/pull/808#discussion_r924021070


##########
pulsar/consumer_impl.go:
##########
@@ -563,6 +566,11 @@ func (c *consumer) Close() {
 		}
 		wg.Wait()
 		close(c.closeCh)
+		closed := closeChanSet[c.messageCh]
+		if !closed {

Review Comment:
   That's what I thought before, but in the case of `multiTopicConsumer` it causes the chan to be closed repeatedly.
   https://github.com/apache/pulsar-client-go/blob/6a8e7f39aac100a285a2c190186e38b73a5c9d34/pulsar/consumer_multitopic_test.go#L46
   ![image](https://user-images.githubusercontent.com/15684156/179652863-b2827370-5415-4e38-a564-e656e4ee438c.png)
   
   
   This is because although the consumers are multiple instances, they use the same `messageCh` and can only be closed once.
   
   So I'd like to record the closed flag for `messageCh` via a global variable.
   
   
   With regard to the `closeChanSet` leak, we can set it to `nil` in the `client.Close()` method.
   https://github.com/apache/pulsar-client-go/blob/6a8e7f39aac100a285a2c190186e38b73a5c9d34/pulsar/client_impl.go#L212
   
   ![image](https://user-images.githubusercontent.com/15684156/179656514-ea84c9de-c873-4f5f-bac9-70946077262a.png)
   
   Is there a better way?
   



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org