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

[bug][cpp] Fix issue where unexpected ack timeout occurred #17503

Merged
merged 1 commit into from
Sep 15, 2022

Conversation

massakam
Copy link
Contributor

@massakam massakam commented Sep 7, 2022

Motivation

When we start a consumer like the following and publish multiple messages to a topic, ack timeout occurs even though the messages received are immediately acknowledged. This does not occur with normal topics, only with partitioned topics.

ClientConfiguration clientConfig;
clientConfig.setMessageListenerThreads(1);
Client client("pulsar://localhost:6650", clientConfig);

ConsumerConfiguration consumerConfig;
consumerConfig.setConsumerType(ConsumerShared);
consumerConfig.setUnAckedMessagesTimeoutMs(10000);
consumerConfig.setMessageListener([](Consumer con, const Message& msg) {
    cout << "Received: " << msg.getDataAsString() << endl;
    con.acknowledge(msg);
    this_thread::sleep_for(chrono::milliseconds(20000));
});

Consumer consumer;
client.subscribe("persistent://public/default/pt4", "sub1", consumerConfig, consumer);

The reason is that the task of executing the message listener function is queued to listenerExecutor_ immediately after adding the message to unAckedMessageTrackerPtr_, but it is not always executed immediately. If it takes a long time to execute each message listener function like the code for reproduction above, it will take a long time for the queued tasks to actually execute, causing an ack timeout. I don't think this is the expected behavior.

unAckedMessageTrackerPtr_->add(msg.getMessageId());
listenerExecutor_->postWork(
std::bind(&MultiTopicsConsumerImpl::internalListener, shared_from_this(), consumer));

Modifications

Have listenerExecutor_ perform adding messages to unAckedMessageTrackerPtr_. In this way, the message listener function will always be executed immediately after adding a message to unAckedMessageTrackerPtr_, preventing unexpected ack timeouts.

Verifying this change

  • Make sure that the change passes the CI checks.

Documentation

  • doc-not-needed

@massakam massakam added type/bug The PR fixed a bug or issue reported a bug component/client-c++ labels Sep 7, 2022
@massakam massakam added this to the 2.11.0 milestone Sep 7, 2022
@massakam massakam self-assigned this Sep 7, 2022
@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Sep 7, 2022
Copy link
Contributor

@BewareMyPower BewareMyPower left a comment

Choose a reason for hiding this comment

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

LGTM. Nice catch!

@github-actions github-actions bot added doc-label-missing and removed doc-not-needed Your PR changes do not impact docs labels Sep 7, 2022
@github-actions
Copy link

github-actions bot commented Sep 7, 2022

@massakam Please provide a correct documentation label for your PR.
Instructions see Pulsar Documentation Label Guide.

@github-actions github-actions bot added doc-not-needed Your PR changes do not impact docs and removed doc-label-missing labels Sep 8, 2022
Copy link
Member

@shibd shibd left a comment

Choose a reason for hiding this comment

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

Nice catch!

@BewareMyPower BewareMyPower merged commit a98f025 into apache:master Sep 15, 2022
@massakam massakam deleted the fix-cpp-ack-timeout branch September 15, 2022 06:09
congbobo184 pushed a commit that referenced this pull request Nov 14, 2022
@congbobo184 congbobo184 added the cherry-picked/branch-2.9 Archived: 2.9 is end of life label Nov 14, 2022
congbobo184 pushed a commit that referenced this pull request Dec 7, 2022
congbobo184 added a commit that referenced this pull request Dec 7, 2022
### Motivation
fix cherry-pick #17609 import
fix cherry-pick #17957  import
fix cherry-pick #16878 lose problem
fix cherry-pick #17503 problem
liangyepianzhou added a commit that referenced this pull request Dec 14, 2022
…8906)

### Motivation
Cherry-pick #17503 to release 2.10.3 and run tests.

### Modifications

Cherry-pick #17503 to release 2.10.3.
nicoloboschi pushed a commit to datastax/pulsar that referenced this pull request Jan 10, 2023
…ache#18906)

### Motivation
Cherry-pick apache#17503 to release 2.10.3 and run tests.

### Modifications

Cherry-pick apache#17503 to release 2.10.3.

(cherry picked from commit b5cfde1)
nicoloboschi pushed a commit to datastax/pulsar that referenced this pull request Jan 11, 2023
…ache#18906)

### Motivation
Cherry-pick apache#17503 to release 2.10.3 and run tests.

### Modifications

Cherry-pick apache#17503 to release 2.10.3.

(cherry picked from commit b5cfde1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-picked/branch-2.9 Archived: 2.9 is end of life cherry-picked/branch-2.10 doc-not-needed Your PR changes do not impact docs release/2.8.5 release/2.9.4 release/2.10.3 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.

7 participants