pulsar-client-go icon indicating copy to clipboard operation
pulsar-client-go copied to clipboard

[Issue 387] fix goroutine leak for closing consumers.

Open crossoverJie opened this issue 3 years ago • 4 comments

Fixes #387

Motivation

Fix goroutine leak for closing consumers.

Modifications

Close the c.messageCh at the same time as closing the consumer.

Before fix:

image image

crossoverJie avatar Jul 14 '22 10:07 crossoverJie

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.

crossoverJie avatar Jul 14 '22 16:07 crossoverJie

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 avatar Jul 15 '22 21:07 pgier

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

crossoverJie avatar Jul 17 '22 05:07 crossoverJie

@Gleiphir2769 Good suggestion, thx.

crossoverJie avatar Aug 22 '22 06:08 crossoverJie