Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unsubscribe blocked when consumer is closing or has closed #457

Merged
merged 2 commits into from Feb 9, 2021

Conversation

wuYin
Copy link
Contributor

@wuYin wuYin commented Jan 29, 2021

Motivation

For the present consumer, Close() and Unsubscribe() handled by the same eventloop goroutine.
The eventloop exited after Close(), then unsubscribe event wouldn't be selected and handled anymore, lead to block.

example:

func main() {
	client, err := pulsar.NewClient(pulsar.ClientOptions{URL: "pulsar://localhost:6650"})
	if err != nil {
		log.Fatal(err)
	}
	defer client.Close()

	consumer, err := client.Subscribe(pulsar.ConsumerOptions{
		Topic:            "topic-1",
		SubscriptionName: "my-sub",
	})
	if err != nil {
		log.Fatal(err)
	}
	
	defer consumer.Unsubscribe() // unintentional
	defer consumer.Close()
}

Unsubscribe() blocked:

image

Modifications

Check consumer state before send unsubscribe event, if consumer is closing or has closed, just logging it

Verifying this change

  • Make sure that the change passes the CI checks.

Copy link
Contributor

@freeznet freeznet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wolfstudy wolfstudy added this to the 0.4.0 milestone Feb 9, 2021
Copy link
Member

@wolfstudy wolfstudy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM +1

@wolfstudy wolfstudy merged commit 25f3075 into apache:master Feb 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants