Skip to content

Commit

Permalink
Fix issue where Key_Shared consumers could get stuck (apache#10920)
Browse files Browse the repository at this point in the history
  • Loading branch information
Masahiro Sakamoto authored and yangl committed Jun 23, 2021
1 parent d190fec commit 95b9dc9
Showing 1 changed file with 7 additions and 1 deletion.
Expand Up @@ -121,8 +121,14 @@ public synchronized void addConsumer(Consumer consumer) throws BrokerServiceExce

@Override
public synchronized void removeConsumer(Consumer consumer) throws BrokerServiceException {
super.removeConsumer(consumer);
// The consumer must be removed from the selector before calling the superclass removeConsumer method.
// In the superclass removeConsumer method, the pending acks that the consumer has are added to
// messagesToRedeliver. If the consumer has not been removed from the selector at this point,
// the broker will try to redeliver the messages to the consumer that has already been closed.
// As a result, the messages are not redelivered to any consumer, and the mark-delete position does not move,
// eventually causing all consumers to get stuck.
selector.removeConsumer(consumer);
super.removeConsumer(consumer);
if (recentlyJoinedConsumers != null) {
recentlyJoinedConsumers.remove(consumer);
if (consumerList.size() == 1) {
Expand Down

0 comments on commit 95b9dc9

Please sign in to comment.