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

[pulsar-broker] If cursor is not durable, close dispatcher when all consumers are removed from subscription #5340

Merged
merged 1 commit into from
Oct 9, 2019

Conversation

massakam
Copy link
Contributor

@massakam massakam commented Oct 8, 2019

Motivation

If cursor is not durable, the subscription is closed and removed from the topic when all consumers are removed.

public synchronized void removeConsumer(Consumer consumer) throws BrokerServiceException {
cursor.updateLastActive();
if (dispatcher != null) {
dispatcher.removeConsumer(consumer);
}
if (dispatcher.getConsumers().isEmpty()) {
deactivateCursor();
if (!cursor.isDurable()) {
// If cursor is not durable, we need to clean up the subscription as well
close();
// when topic closes: it iterates through concurrent-subscription map to close each subscription. so,
// topic.remove again try to access same map which creates deadlock. so, execute it in different thread.
topic.getBrokerService().pulsar().getExecutor().submit(() ->{
topic.removeSubscription(subName);
});
}
}

As mentioned in #5288, the dispatcher also needs to be closed at this time. Otherwise, RateLimiter instances will not be garbage collected, causing a memory leak.

@massakam massakam added this to the 2.4.2 milestone Oct 8, 2019
@massakam massakam self-assigned this Oct 8, 2019
@massakam
Copy link
Contributor Author

massakam commented Oct 9, 2019

rerun java8 tests
rerun integration tests

@jiazhai jiazhai merged commit 136048c into apache:master Oct 9, 2019
@massakam massakam deleted the close-non-durable-dispatcher branch October 9, 2019 08:05
wolfstudy pushed a commit that referenced this pull request Nov 20, 2019
…oved from subscription (#5340)

### Motivation

If cursor is not durable, the subscription is closed and removed from the topic when all consumers are removed. 
https://github.com/apache/pulsar/blob/413ba03050036a620fa346456ef6c3ff6071e9ab/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentSubscription.java#L237-L254

As mentioned in #5288, the dispatcher also needs to be closed at this time. Otherwise, `RateLimiter` instances will not be garbage collected, causing a memory leak.

(cherry picked from commit 136048c)
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