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] Fix one potential to add duplicated consumer by TakaHiR07 · Pull Request #20583 · apache/pulsar

Conversation

@TakaHiR07

@TakaHiR07 TakaHiR07 commented Jun 15, 2023 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Fixes #20576

Motivation

There is a case resulted in duplicated consumer, if we add the same consumer twice continuously, then close consumer, the offline consumer would remain in consumerList, because AbstractDispatcherMultipleConsumers#consumerList is arrayList and AbstractDispatcherMultipleConsumers#consumerSet is set.

There is a concurrent problem in ServerCnx#handleSubscribe, which cause this case. Suppose client request handleSubscribe() three times and request handleCloseConsumer(). The execute order is as follow. since the order is addConsumer->addConsumer->close, but not addConsumer->close->addConsumer, duplicated consumer problem occur.

企业微信截图_1ea4ed11-3c2b-4e46-94a8-aad1be312b93

Modifications

  1. remove the step 9 "consumersLongHashmap.remove consumerFuture3".
  • Because if judge existingConsumerFuture is not null, it means there is an earlier request try to handleSubscribe. the remove operation should be executed in the earlier request.
  1. add a test to verify this concurrent problem and the fix

Verifying this change

  • Make sure that the change passes the CI checks.

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository: TakaHiR07#10

Sorry, something went wrong.

Uh oh!

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

All reactions
fanjianye
fix one potential to add duplicated consumer
4085518
@github-actions github-actions Bot added the doc-not-needed Your PR changes do not impact docs label Jun 15, 2023
@eolivelli

eolivelli commented Jun 15, 2023

Copy link
Copy Markdown
Contributor

You say in the linked issue and you have seen this twice.
Are you able to reproduce it manually and verify that with this fix the problem is really fixed?

All reactions

Sorry, something went wrong.

Uh oh!

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

@TakaHiR07

TakaHiR07 commented Jun 15, 2023

Copy link
Copy Markdown
Contributor Author

You say in the linked issue and you have seen this twice. Are you able to reproduce it manually and verify that with this fix the problem is really fixed?

I guess this is one of the possibilities for duplicated consumer. And this pr is corresponding to our production case. I can't affirm the duplicated consumer problem do not occur anymore.

All reactions

Sorry, something went wrong.

Uh oh!

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

@TakaHiR07

TakaHiR07 commented Jun 16, 2023

Copy link
Copy Markdown
Contributor Author

@poorbarcode @eolivelli @lhotari @congbobo184 Can you help review this pr? It is another possibilities besides #15051

All reactions

Sorry, something went wrong.

Uh oh!

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

poorbarcode
poorbarcode reviewed Jun 16, 2023
View reviewed changes
Comment thread pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
ServerError error = getErrorCodeWithErrorLog(existingConsumerFuture, true,
String.format("Consumer subscribe failure. remoteAddress: %s, subscription: %s",
remoteAddress, subscriptionName));
consumers.remove(consumerId, existingConsumerFuture);

@poorbarcode poorbarcode Jun 16, 2023

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.

There are three clients in your example, the pulsar client maintains its own connection pool, which means the client1 will not use the same connection as client2 or client3.

The code you changed is the code of ServerCnx(this object is not shared across multi clients), so it will not affect other consumers of other clients

Sorry, something went wrong.

Uh oh!

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

All reactions

@poorbarcode poorbarcode Jun 16, 2023

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.

Additional background:

If you have two pulsar clients, the consumers registered will be like this:

  • pulsar-client-1
    • connection-1 (one-to-one relationship with ServerCnx)
      • consumer-1
      • consumer-2
    • connection-2
      • consumer-3
      • consumer-4
  • pulsar-client-2
    • connection-3
      • consumer-5
      • consumer-6
    • connection-4
      • consumer-7
      • consumer-8

Sorry, something went wrong.

Uh oh!

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

All reactions

@poorbarcode poorbarcode Jun 16, 2023

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.

So only consumer-1 and consumer-2 can be in conflict since their consumer-id is not the same, so all things are OK.

Sorry, something went wrong.

Uh oh!

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

All reactions

@TakaHiR07 TakaHiR07 Jun 16, 2023

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 guess it is one client request three times. Because in our server log, "Subscribing on topic" occur three times in a short time from the same remoteAddress host:ip. Therefore they are in the same connection ?

Sorry, something went wrong.

Uh oh!

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

All reactions

@poorbarcode poorbarcode Jun 16, 2023

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.

I guess it is one client request three times. Because in our server log, "Subscribing on topic" occur three times in a short time from the same remoteAddress host:ip. Therefore they are in the same connection ?

could you provide the logs?

Sorry, something went wrong.

Uh oh!

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

All reactions

@poorbarcode poorbarcode Jun 16, 2023

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.

By the log, we can not confirm if these three consumers are the same, because we can not know their consumer id. This log was been improved in the PR https://github.com/apache/pulsar/pull/20568/files#diff-1e0e8195fb5ec5a6d79acbc7d859c025a9b711f94e6ab37c94439e99b3202e84R1168

Sorry, something went wrong.

Uh oh!

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

All reactions

@poorbarcode poorbarcode Jun 16, 2023 •
edited
Loading

Uh oh!

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

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.

time req-1 req-2 close connection
1 put a new consumerFuture
2 close connection
3 mark the consumerFuture as failed
4 close the connection
5 got consumerFuture(failed)
6 remove the failed future
7 add the consumer into the list and set(list.size = 1 and set.size = 1)
8 put the second consumerFuture
9 add the second consumer into the list and set(list.size = 2 and set.size = 1)
10 remove the consumer from the list and set(list.size = 1 and set.size = 0)

Do you want to say the three requests executed as above?

  • before the step-4 and after step-4, there are two different connections
  • if the req-1 runs at the first connection, it will trigger another consumer.close. see: https://github.com/apache/pulsar/blob/master/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java#L896
    • (Highlight)But maybe left an orphan consumer in the consumer list, see: https://github.com/apache/pulsar/blob/master/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java#L203. I think you can write a test to reproduce this case.
  • if the req-1 runs at the second connection, all things are OK. Just like the comment above [fix][broker] Fix one potential to add duplicated consumer #20583 (comment)

Sorry, something went wrong.

Uh oh!

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

All reactions

@TakaHiR07 TakaHiR07 Jun 16, 2023

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

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

@poorbarcode poorbarcode Jun 16, 2023

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.

BTW, there is a PR trying to fix the concurrent call subscribe in the same client

  • [fix] [client] Messages lost when consumer reconnect #20591

I still think the current PR is trying to solve this issue is meaningful, and it would be nice to have a test that can reproduce it.

Sorry, something went wrong.

Uh oh!

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

All reactions

@poorbarcode poorbarcode Mar 19, 2024 •
edited
Loading

Uh oh!

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

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.

@TakaHiR07

Could you take a look at this PR #22283 , #22270 and modify the current one? If yes, I will close #22283, #22270 ❤️

Sorry, something went wrong.

Uh oh!

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

All reactions
@TakaHiR07
TakaHiR07 force-pushed the fix_potential_to_add_duplicated_consumer branch from 7bbfba5 to e4f561b Compare June 25, 2023 12:46
fanjianye
add test for concurrently created consumer
fbebced
@TakaHiR07
TakaHiR07 force-pushed the fix_potential_to_add_duplicated_consumer branch from e4f561b to fbebced Compare June 25, 2023 12:48
@TakaHiR07

TakaHiR07 commented Jun 25, 2023 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

Add a test to verify this concurrent case and the fix. PTAL, thanks. @codelipenghui @eolivelli @lhotari @poorbarcode

All reactions

Sorry, something went wrong.

Uh oh!

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

@Technoboy- Technoboy- added this to the 3.2.0 milestone Jul 31, 2023
@github-actions

github-actions Bot commented Aug 31, 2023

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 Stale label Aug 31, 2023
@codelipenghui codelipenghui added the category/reliability The function does not work properly in certain specific environments or failures. e.g. data lost label Sep 19, 2023
@codelipenghui codelipenghui assigned TakaHiR07 Oct 7, 2023
@Technoboy- Technoboy- modified the milestones: 3.2.0, 3.3.0 Dec 22, 2023
@graysonzeng

graysonzeng commented Jan 31, 2024 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

I had the same problem on flink task and got fixed after trying this PR.

All reactions

Sorry, something went wrong.

Uh oh!

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

@TakaHiR07

TakaHiR07 commented Mar 18, 2024

Copy link
Copy Markdown
Contributor Author

@poorbarcode @codelipenghui It seems this problem is not fixed in the master branch.

All reactions

Sorry, something went wrong.

Uh oh!

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

@Technoboy- Technoboy- mentioned this pull request Mar 19, 2024
[fix] [broker] fix mismatch between dispatcher.consumerList and dispatcher.consumerSet #22283
Merged
1 of 4 tasks
@coderzc coderzc modified the milestones: 3.3.0, 3.4.0 May 8, 2024
@TakaHiR07

TakaHiR07 commented May 20, 2024

Copy link
Copy Markdown
Contributor Author

#22283 has fixed the same problem. Close this pr.

All reactions

Sorry, something went wrong.

Uh oh!

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

@TakaHiR07 TakaHiR07 closed this May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@poorbarcode poorbarcode poorbarcode left review comments

Uh oh!

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

Assignees

@TakaHiR07 TakaHiR07

Labels

category/reliability The function does not work properly in certain specific environments or failures. e.g. data lost doc-not-needed Your PR changes do not impact docs Stale

Projects

None yet

Milestone

4.0.0

Development

Successfully merging this pull request may close these issues.

[Bug] [broker] subscription of topic in a permanent fence state and consumerList remain offline consumer

Uh oh!

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

7 participants

@TakaHiR07 @eolivelli @graysonzeng @poorbarcode @Technoboy- @codelipenghui @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.