Skip to content

Conversation

@lhotari
Copy link
Member

@lhotari lhotari commented Sep 15, 2021

Fixes #12024

Motivation

See #12024 for details. The PR #11843 changes causes a critical cleanup problem in the Pulsar Client 2.8.1. for multi-topic consumers.

Modifications

Ignore AlreadyClosedExceptions in the exceptionally handler which was added in PR #11843

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

good catch !

+1
I am sure that you know better than me that those Thread.sleep() smell a little, but I am not sure how to do it without adding more and more instrumentation (probably with Powermock?)

@lhotari lhotari added the doc-not-needed Your PR changes do not impact docs label Sep 15, 2021
.subscribe();

// wait for background tasks to start
Thread.sleep(1000L);
Copy link
Contributor

Choose a reason for hiding this comment

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

We cannot be sure that this task can be started within 1 second.
I think we should use awaitility

Copy link
Member

Choose a reason for hiding this comment

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

Given the implementation of internalReceiveAsync in MultiTopicConsumerImpl, I think it would be sufficient to modify this test to await the receipt of a single message from the multi topic consumer. After receiving a single message, the individual topic consumer will be added to the pendingReceives queue and will subsequently be failed with an AlreadyClosedException when the multi topic consumer is closed. That exception will then be handled in receiveMessageFromConsumer and will exercise the fix in this PR. The one downside to this implementation is that our test would be tightly coupled to the implementation. Let me know what you think, @lhotari.

Copy link
Member

@michaeljmarshall michaeljmarshall left a comment

Choose a reason for hiding this comment

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

LGTM. I think we can improve the test, please see my comment.

Note: this bug leads to a leak of runnable tasks in some cases. For example, when we have a topic consumer in the pendingConsumers queue and we close the multi topic consumer, we'll fail the futures and get into this infinite retry loop. If the pulsar client is left open for a while, and multi topic consumers are opened and closed many times, the number of runnable tasks will continue to increase with each new consumer. Note that if the pulsar client itself is closed, the internal executor service is closed, which stops the leak.

.subscribe();

// wait for background tasks to start
Thread.sleep(1000L);
Copy link
Member

Choose a reason for hiding this comment

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

Given the implementation of internalReceiveAsync in MultiTopicConsumerImpl, I think it would be sufficient to modify this test to await the receipt of a single message from the multi topic consumer. After receiving a single message, the individual topic consumer will be added to the pendingReceives queue and will subsequently be failed with an AlreadyClosedException when the multi topic consumer is closed. That exception will then be handled in receiveMessageFromConsumer and will exercise the fix in this PR. The one downside to this implementation is that our test would be tightly coupled to the implementation. Let me know what you think, @lhotari.

@merlimat merlimat merged commit bb80c5b into apache:master Sep 16, 2021
@codelipenghui codelipenghui added the cherry-picked/branch-2.8 Archived: 2.8 is end of life label Sep 18, 2021
eolivelli pushed a commit to datastax/pulsar that referenced this pull request Sep 24, 2021
bharanic-dev pushed a commit to bharanic-dev/pulsar that referenced this pull request Mar 18, 2022
aloyszhang pushed a commit to aloyszhang/pulsar that referenced this pull request Aug 5, 2022
…erge request !100)

Squash merge branch 'consumer-close' into '2.8.1'
修复 MQ proxy 消费者关闭之后,打印大量错误日志 的问题

TAPD: --bug=102239121
Shawyeok pushed a commit to Shawyeok/pulsar that referenced this pull request Sep 6, 2022
aloyszhang pushed a commit to aloyszhang/pulsar that referenced this pull request Jan 9, 2023
…erge request !100) (merge request !101)

Squash merge branch 'consumer-loop' into 'release-2.8.1.4'
消费者关闭之后,打印大量错误日志

TAPD: --bug=102239121
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/client cherry-picked/branch-2.8 Archived: 2.8 is end of life doc-not-needed Your PR changes do not impact docs release/2.8.2 release/2.9.0 type/bug The PR fixed a bug or issue reported a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Endless receive retries on closed consumer

6 participants