pulsar-client-go
pulsar-client-go copied to clipboard
[Issue 387] fix goroutine leak for closing consumers.
Fixes #387
Motivation
Fix goroutine leak for closing consumers.
Modifications
Close the c.messageCh at the same time as closing the consumer.
Before fix:

Is there any chance that c.messageCh can be nil? Just wondering if we need a nil check around closing it since trying to close a nil channel can cause a panic. Otherwise LGTM
Thanks for the reminder. https://github.com/apache/pulsar-client-go/blob/6a8e7f39aac100a285a2c190186e38b73a5c9d34/pulsar/consumer_impl.go#L101 Initialization is done when the consumer is created.
Looks like there is a failure in one of the tests that we're trying to close an already closed channel. I guess in some cases the channel gets closed and others it doesn't?
@pgier PTAL, already adjusted.
The regexConsumer and multiTopicConsumer share the same messageCh within the same consumer, so they only need to be closed once.
This is the reason why chan was closed repeatedly before.
@Gleiphir2769 Good suggestion, thx.