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

Fix ack failure on message listener in multi topics consumer #447

Merged
merged 2 commits into from
Oct 11, 2024

Conversation

nkurihar
Copy link
Contributor

@nkurihar nkurihar commented Oct 2, 2024

Fixes #446

Motivation

We found an ack failure issue: #446

MessageListeners can start to process messages before subscribing all child topics are completed in "multi topics" (e.g. partitioned, list, regex) cases.
If acknowledge() is called in messageListeners (it is very typical usage) before subscribing completion, it will fail with AlreadyClosed error since the state of the parent consumer is not Ready yet:

void MultiTopicsConsumerImpl::acknowledgeAsync(const MessageId& msgId, ResultCallback callback) {
if (state_ != Ready) {
interceptors_->onAcknowledge(Consumer(shared_from_this()), ResultAlreadyClosed, msgId);
callback(ResultAlreadyClosed);
return;
}

That results in ack holes, and finally full backlog.

Modifications

  • MultiTopicsConsumerImpl: Pause messageListeners at first by setting startPaused to true and resume them after subscribing all child topics are completed.
  • ConsumerImpl: Delete unused code.
    • It tries to skip sendFlowPermitsToBroker() at the first connection.
      • The motivation seems same as this PR, i.e. to prevent messageListeners from starting before subscribing completion.
    • However, actually it does not work so far, the variable firstTime looks always false at
      if (consumerTopicType_ == NonPartitioned || !firstTime) {
      because it becomes false at
      if (firstTime) {
      firstTime = false;
      }
      • Also it is static variable in a method that is shared by all ConsumerImpl instances, whereas it has no chance of returning to true once it becomes false.
    • It seems better that child consumers don't have to care about their parents and are completely independent of them.

Verifying this change

  • Make sure that the change passes the CI checks.

Specific tests for this issue is difficult to implement because it does not occur every time.

Documentation

  • doc-required
    (Your PR needs to update docs and you will update later)

  • doc-not-needed
    (Please explain why)

  • doc
    (Your PR contains doc changes)

  • doc-complete
    (Docs have been already added)

@nkurihar nkurihar added the bug Something isn't working label Oct 3, 2024
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.

Could you add a test for it?

@BewareMyPower BewareMyPower added this to the 3.7.0 milestone Oct 11, 2024
@BewareMyPower
Copy link
Contributor

Specific tests for this issue is difficult to implement because it does not occur every time.

Okay, I see it.

@BewareMyPower BewareMyPower merged commit 54e529a into apache:main Oct 11, 2024
14 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Ack failure on message listener in multi topics consumer
2 participants