GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [fix][broker] The offline consumer is not removed from the consumerList by lordcheng10 · Pull Request #14970 · apache/pulsar

Conversation

@lordcheng10

@lordcheng10 lordcheng10 commented Mar 31, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Motivation

We found a problem: when the consumer was removed, it was not removed from the consumerList, but it was removed from the consumerSet and consumers:

image

The log to remove the consumer is as follows:

10:31:40.404 [BookKeeperClientWorker-OrderedExecutor-30-0] INFO org.apache.pulsar.broker.service.persistent.PersistentDispatcherMultipleConsumers - Removed consumer Consumer{subscription=PersistentSubscription{topic=persistent://teg_onion_onion_logcenter_data_gz/teg_onion_onion_logcenter_data_gz/teg_onion_onion_logcenter_data_gz-partition-51, name=t_teg_onion_b_teg_onion_onion_logcenter_data_gz_cg_consumer_001}, consumerId=51, consumerName=ff7f4103a3, address=/11.181.202.252:55902} with pending 0 acks

Documentation

Check the box below or label this PR directly (if you have committer privilege).

Need to update docs?

  • doc-required

    (If you need help on updating docs, create a doc issue)

  • no-need-doc

    (Please explain why)

  • doc

    (If this PR contains doc changes)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@lordcheng10
remove all consumer from consumerList
4d3a3ae
@xuesongxs

xuesongxs commented Mar 31, 2022

Copy link
Copy Markdown
Contributor

#13787
Just like this bug.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot assigned lordcheng10 Mar 31, 2022
@github-actions github-actions Bot added the doc-not-needed Your PR changes do not impact docs label Mar 31, 2022
@Technoboy- Technoboy- changed the title Fix:The offline consumer is not removed from the consumerList [fix][broker] The offline consumer is not removed from the consumerList Mar 31, 2022
lhotari
lhotari requested changes Mar 31, 2022
View reviewed changes

@lhotari lhotari left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Good catch. I wonder if it would be better to prevent adding duplicates to the list and doing a check in addConsumer? I think that would be a better solution to the problem.
I also have a suggestion to use removeIf there isn't a way to prevent duplicates getting added to the list.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mattisonchao reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread .../java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java Outdated
addUnAckedMessages(-consumer.getUnackedMessages());
if (consumerSet.removeAll(consumer) == 1) {
consumerList.remove(consumer);
removeAllConsumer(consumer);

@lhotari lhotari Mar 31, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The removeAllConsumer doesn't look great. I wonder if using .removeIf would be better:

Suggested change
removeAllConsumer(consumer);
consumerList.removeIf(consumer::equals);

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

poorbarcode reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@michaeljmarshall michaeljmarshall Mar 31, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I agree with this sentiment. I wonder about the data structure itself, too. Why is it a list and not a set?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@eolivelli eolivelli Mar 31, 2022

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

+1 to @lhotari 's suggestion

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lordcheng10 lordcheng10 Mar 31, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I agree to @lhotari 's suggestion

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lordcheng10 lordcheng10 Apr 1, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Fixed:
1.do a check in addConsumer;
2.use removeIf;

PTAL,thanks! @lhotari @eolivelli

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lhotari lhotari Apr 1, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

@lordcheng10 there's a minor checkstyle issue in the recent changes. please check that

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lordcheng10 lordcheng10 Apr 1, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Fixed.
PTAL,thanks! @lhotari

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@lhotari
lhotari requested review from eolivelli and michaeljmarshall March 31, 2022 16:53
@lordcheng10

lordcheng10 commented Mar 31, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

In fact, the problem here may be the problem of consumer equality, similar to the previous producer problem.

When there are duplicate consumers in the consumerList, it is possible to remove the actually successfully registered consumers when removing them.

In our scenario, we also found a problem: when the consumer reconnects, the broker no longer pushes messages to these consumers. Through the stats command, we see these The consumer's permit is 0, and it is a consumer that has been removed from the consumerSet and consumers. The wrong consumer could be removed .
image

image

image

So the fundamental problem here is actually the definition of consumer equality. I think we might need to do something like #12846 on the definition of equality for consumers.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lordcheng10

lordcheng10 commented Mar 31, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

I think we also need to implement a method similar to isSuccessorTo to determine whether the consumer can be overridden, what do you think? @lhotari @michaeljmarshall @eolivelli

like this:

public boolean isSuccessorTo(Consumer other){
    return Objects.equals(cnx.clientAddress(), other.cnx.clientAddress()) && consumerId == other.consumerId
            &&  other.consumerEpoch < consumerEpoch;
}
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@michaeljmarshall

michaeljmarshall commented Mar 31, 2022

Copy link
Copy Markdown
Member

@lordcheng10 - that is a great finding. I think it seems very reasonable to adjust the consumer logic, but I still haven't researched the consumer remove logic, so I am not authoritative on the subject. I wonder if we'd be able to add a test that shows the isSuccessorTo logic is necessary.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

lordcheng10 added 2 commits April 1, 2022 10:46
@lordcheng10
1.do a check in addConsumer;
eb75a3c
2.use removeIf;
@lordcheng10
check style
fc1d0b5
eolivelli
eolivelli reviewed Apr 1, 2022
View reviewed changes
Comment thread .../java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java Outdated
log.warn("[{}] Consumer with the same id is already created:"
+ " consumerId={}, consumer={}",
consumer.cnx().clientAddress(), consumer.consumerId(), consumer);
throw new BrokerServiceException("Consumer with the same id is already created!");

@eolivelli eolivelli Apr 1, 2022

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

what about using ConsumerBusyException ?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lordcheng10 lordcheng10 Apr 1, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Fixed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread .../java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java Outdated
+ " consumerId={}, consumer={}",
consumer.cnx().clientAddress(), consumer.consumerId(), consumer);
throw new BrokerServiceException("Consumer with the same id is already created!");

@eolivelli eolivelli Apr 1, 2022

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

nit: remove useless newline

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lordcheng10 lordcheng10 Apr 1, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Fixed. PTAL,thanks! @eolivelli

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@lordcheng10
1.use ConsumerBusyException;
e1c9596
2.remove useless newline;
eolivelli
eolivelli approved these changes Apr 1, 2022
View reviewed changes

@eolivelli eolivelli left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM

although adding a test will help in understanding how to reproduce the problem

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@lordcheng10

lordcheng10 commented Apr 1, 2022

Copy link
Copy Markdown
Contributor Author

/pulsarbot run-failure-checks

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lordcheng10
lordcheng10 requested a review from lhotari April 1, 2022 08:06
@lordcheng10

lordcheng10 commented Apr 1, 2022

Copy link
Copy Markdown
Contributor Author

/pulsarbot run-failure-checks

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Jason918
Jason918 reviewed Apr 1, 2022
View reviewed changes
Comment thread .../java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java
throw new ConsumerBusyException("Subscription reached max consumers limit");
}

if (consumerList.contains(consumer)) {

@Jason918 Jason918 Apr 1, 2022

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Can you provide the case of duplicated consumer?
I wonder if we should replace the old consumer with the new one. The older consumer maybe somewhat expired.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lordcheng10 lordcheng10 Apr 1, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Yes so I think we should write a method like org.apache.pulsar.broker.service.Producer#isSuccessorTo to judge whether the previous consumer object should be overwritten by consumerEpoch,like this:

public boolean isSuccessorTo(Consumer other){
return Objects.equals(cnx.clientAddress(), other.cnx.clientAddress()) && consumerId == other.consumerId
&& other.consumerEpoch < consumerEpoch;
}

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lordcheng10 lordcheng10 Apr 1, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Can you provide the case of duplicated consumer?

OK, I will try to find duplicate cases.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Jason918 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@lordcheng10

lordcheng10 commented Apr 1, 2022

Copy link
Copy Markdown
Contributor Author

/pulsarbot run-failure-checks

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Apr 6, 2022
Broker registered the same consumers #15050
Closed
[fix][broker] Fix potential to add duplicated consumer #15051
Merged
@sijie sijie mentioned this pull request Apr 6, 2022
ISSUE-15050: Broker registered the same consumers streamnative/pulsar-archived#4029
Open
@github-actions

github-actions Bot commented May 2, 2022

Copy link
Copy Markdown

The pr had no activity for 30 days, mark with Stale label.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the lifecycle/stale label May 2, 2022
@github-actions

github-actions Bot commented Jun 2, 2022

Copy link
Copy Markdown

The pr had no activity for 30 days, mark with Stale label.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lhotari lhotari mentioned this pull request Jul 15, 2022
[Java Client] Send CloseConsumer on client timeout #16616
Merged
1 task done
@TakaHiR07 TakaHiR07 mentioned this pull request Jun 14, 2023
[Bug] [broker] subscription of topic in a permanent fence state and consumerList remain offline consumer #20576
Closed
2 tasks done
@Technoboy- Technoboy- added this to the 3.2.0 milestone Jul 31, 2023
@Technoboy- Technoboy- modified the milestones: 3.2.0, 3.3.0 Dec 22, 2023
@coderzc coderzc modified the milestones: 3.3.0, 3.4.0 May 8, 2024
@lhotari lhotari modified the milestones: 4.0.0, 4.1.0 Oct 14, 2024
@coderzc coderzc modified the milestones: 4.1.0, 4.2.0 Sep 1, 2025
@merlimat

merlimat commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Thanks @lordcheng10 for finding this. Your report about stale consumers in consumerList was right. Master has since fixed it in other ways: #15051 prevents the duplicate registration, #22270/#22283 fix list/set mismatches, and #26652 now removes only the exact consumer instance. Note that removeIf(consumer::equals) would also remove a live replacement consumer with the same id and address. I'm closing this as superseded. If you still see a dead consumer that keeps getting dispatched messages on a current release, please open an issue with the broker version and the stats output.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@merlimat merlimat closed this Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@Jason918 Jason918 Jason918 left review comments
@eolivelli eolivelli eolivelli approved these changes
@michaeljmarshall michaeljmarshall Awaiting requested review from michaeljmarshall
@lhotari lhotari Awaiting requested review from lhotari

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@lordcheng10 lordcheng10

Labels

doc-not-needed Your PR changes do not impact docs lifecycle/stale Stale

Projects

None yet

Milestone

4.2.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

9 participants

@lordcheng10 @xuesongxs @michaeljmarshall @merlimat @lhotari @Jason918 @eolivelli @Technoboy- @coderzc
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.