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][client] Queue acks without grouping while the consumer is reconnecting by poorbarcode · Pull Request #21928 · apache/pulsar

Conversation

@poorbarcode

@poorbarcode poorbarcode commented Jan 18, 2024 •
edited by merlimat
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Motivation

With acknowledgmentGroupTime(0), acks skip the grouping tracker and are sent straight away by
doImmediateAck / doImmediateBatchIndexAck in PersistentAcknowledgmentsGroupingTracker. When the
consumer is reconnecting (after a topic unload, a broker restart or a network blip):

  • ConnectionHandler.connectionClosed sets the connection to null and the state to Connecting, and
    ConsumerImpl.doAcknowledge still accepts acks in Connecting. doImmediateAck then fails the ack
    with ConnectException("Consumer connect fail! consumer state:Connecting").
  • ConsumerImpl.connectionOpened sets the new connection before it sends SUBSCRIBE. An ack written
    before the broker has registered the consumer is dropped by ServerCnx.handleAck, which only logs it
    at debug level when there's no request id.

In both cases the broker redelivers the message after the reconnect, so the application sees it twice.
The V5 client inherits this: acknowledgmentGroupTime(Duration.ZERO) sets the same configuration, and
ScalableQueueConsumer.acknowledge ignores the future, so the failure isn't visible at all.

Example on master:

Consumer<String> consumer = client.newConsumer(Schema.STRING)
        .topic(topic).subscriptionName("sub")
        .acknowledgmentGroupTime(0, TimeUnit.MILLISECONDS)
        .subscribe();
Message<String> msg = consumer.receive();
admin.topics().unload(topic);   // the consumer is now Connecting, without a connection
consumer.acknowledge(msg);      // throws PulsarClientException.ConnectException; msg is redelivered

Grouped acks (group time > 0) were not affected: they stay pending and the periodic flush retries them.

Modifications

  • PersistentAcknowledgmentsGroupingTracker sends an ack immediately only when it has properties
    (compaction, unchanged) or when there's no group time and the consumer is subscribed. The consumer is
    subscribed when it has a connection and its state isn't Connecting. Otherwise the ack is added to the
    group, and with no group time the tracker flushes right after adding it.
  • flush() only writes to a subscribed consumer's connection, so grouped acks are no longer written
    before the subscribe completes. They wait for the next flush instead.
  • ConsumerImpl.connectionOpened flushes the tracker once the subscribe succeeds. That sends the acks that
    waited, which matters when there's no group time because no periodic flush runs then.

This is based on the original change by @poorbarcode, reworked after the review: the queueing takes the
regular grouping path instead of passing a boolean through each method.

Verifying this change

  • AcknowledgementsGroupingTrackerTest#testImmediateAcksWaitForTheSubscription: individual and cumulative
    acks made while the consumer is Connecting don't fail and don't touch the connection. The next flush
    sends them.
  • AcknowledgementsGroupingTrackerTest#testImmediateAckingTracker now expects a disconnected ack to wait
    for the flush instead of failing.
  • ConsumerAckTest#testAckWithoutGroupingWhileReconnecting (individual and cumulative): an ack made after
    an unload, while the consumer has no connection, is applied after the reconnect and the backlog drops to 0.

Sorry, something went wrong.

Uh oh!

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

All reactions
poorbarcode added 2 commits January 19, 2024 01:23
@poorbarcode
-
b5ef8d4
@poorbarcode
[fix] [client] Fix ack failed due to reconnecting
f6a748b
@poorbarcode poorbarcode self-assigned this Jan 18, 2024
@poorbarcode poorbarcode added the type/bug The PR fixed a bug or issue reported a bug label Jan 18, 2024
@poorbarcode poorbarcode added this to the 3.3.0 milestone Jan 18, 2024
@poorbarcode poorbarcode added release/2.10.6 release/3.0.3 release/2.11.4 release/3.1.3 release/3.2.1 labels Jan 18, 2024
@github-actions github-actions Bot added the doc-not-needed Your PR changes do not impact docs label Jan 18, 2024
@poorbarcode
poorbarcode requested review from BewareMyPower, Technoboy-, codelipenghui and liangyepianzhou January 18, 2024 18:05
@poorbarcode poorbarcode added the category/reliability The function does not work properly in certain specific environments or failures. e.g. data lost label Jan 18, 2024
codelipenghui
codelipenghui reviewed Jan 19, 2024
View reviewed changes
Comment thread pulsar-broker/src/test/java/org/apache/pulsar/client/api/SimpleProducerConsumerTest.java Resolved

Uh oh!

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

Comment thread pulsar-broker/src/test/java/org/apache/pulsar/client/api/SimpleProducerConsumerTest.java Resolved

Uh oh!

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

Comment thread pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java Resolved

Uh oh!

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

Comment thread ...nt/src/main/java/org/apache/pulsar/client/impl/PersistentAcknowledgmentsGroupingTracker.java Resolved

Uh oh!

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

BewareMyPower
BewareMyPower reviewed Jan 19, 2024
View reviewed changes
Comment thread ...nt/src/main/java/org/apache/pulsar/client/impl/PersistentAcknowledgmentsGroupingTracker.java Resolved

Uh oh!

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

@poorbarcode poorbarcode changed the title [fix] [client] fix ack failed when consumer is reconnecting [draft] [fix] [client] fix ack failed when consumer is reconnecting Jan 21, 2024
@poorbarcode
address commnents
4b5ebd3
@coderzc coderzc modified the milestones: 3.3.0, 3.4.0 May 8, 2024
@lhotari lhotari added release/3.0.8 and removed release/3.0.3 labels Oct 10, 2024
@lhotari lhotari modified the milestones: 4.0.0, 4.1.0 Oct 11, 2024
@lhotari

lhotari commented Oct 14, 2024

Copy link
Copy Markdown
Member

Please rebase

All reactions

Sorry, something went wrong.

Uh oh!

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

@lhotari lhotari added the triage/lhotari/important lhotari's triaging label for important issues or PRs label Oct 14, 2024
@lhotari

lhotari commented Nov 22, 2024

Copy link
Copy Markdown
Member

@poorbarcode Please rebase

All reactions

Sorry, something went wrong.

Uh oh!

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

@lhotari lhotari removed the release/3.0.8 label Dec 6, 2024
@lhotari lhotari added release/4.2.3 and removed release/4.2.2 labels Jun 8, 2026
@lhotari lhotari added release/4.2.4 and removed release/4.2.3 labels Jun 30, 2026
@lhotari lhotari added release/4.2.5 and removed release/4.2.4 labels Jul 27, 2026
@lhotari lhotari added release/4.2.6 and removed release/4.2.5 labels Oct 14, 2026
merlimat added 2 commits October 22, 2026 16:09
@merlimat
Merge remote-tracking branch 'apache/master' into mmerli/adopt-21928-…
3b221cb
…ack-reconnect

Signed-off-by: Matteo Merli <[email protected]>

# Conflicts:
#	pulsar-broker/src/test/java/org/apache/pulsar/client/api/SimpleProducerConsumerTest.java
#	pulsar-client/src/main/java/org/apache/pulsar/client/impl/PersistentAcknowledgmentsGroupingTracker.java
@merlimat
[fix][client] Queue acks without grouping while the consumer is recon…
742a4ad
…necting

With acknowledgmentGroupTime=0, an ack issued while the consumer had no
connection failed with ConnectException, and one issued after the
reconnect but before the subscribe response could be dropped by the
broker. The message was then redelivered.

Such acks now wait in the group and are sent by the flush that follows
the subscription. Acks with properties (compaction) keep the immediate
path.
@merlimat merlimat modified the milestones: 5.0.0-M1, 5.1.0 Oct 22, 2026
@merlimat merlimat added release/5.0.2 and removed release/2.10.6 release/2.11.4 release/3.1.3 release/3.2.1 release/3.0.18 release/4.2.6 labels Oct 22, 2026
@merlimat merlimat changed the title [draft] [fix] [client] fix ack failed when consumer is reconnecting [fix][client] Queue acks without grouping while the consumer is reconnecting Oct 22, 2026
@merlimat

merlimat commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

@poorbarcode this is still reproducible on master: with acknowledgmentGroupTime(0), doImmediateAck fails when the consumer is reconnecting, and the V5 client drops that failure silently. Since you're busy elsewhere, I've picked it up here. I merged master and re-implemented the fix along the lines of @BewareMyPower's suggestion. Acks without properties go through the regular grouping path while the consumer isn't subscribed, and they're flushed once the subscribe succeeds. This also covers acks sent on the new connection before the subscribe response arrives, which the broker drops. I've updated the title and description accordingly. PTAL @BewareMyPower @codelipenghui

All reactions

Sorry, something went wrong.

Uh oh!

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

merlimat
merlimat approved these changes Oct 22, 2026
View reviewed changes
@merlimat
merlimat merged commit 4060cce into apache:master Oct 23, 2026
44 checks passed

Uh oh!

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

This was referenced Oct 23, 2026
[fix][client] Flush the pending acks before the flow command when the consumer reconnects #27062
Merged
[fix][client] Stop the partition update timer of a partitioned producer that ended during creation #27061
Merged
@merlimat merlimat mentioned this pull request Oct 23, 2026
[fix][test] Fix flaky V5CumulativeAckTest.testRetryingAnAckThatFailedWhileDisconnectedAdvancesTheCursor #27070
Merged
11 tasks
@void-ptr974 void-ptr974 mentioned this pull request Oct 24, 2026
[fix][client] Fix ACK timeout backoff deadlocks during receive and redelivery #27065
Merged
1 of 11 tasks
This was referenced Nov 21, 2026
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27680
Closed
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27681
Closed
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27684
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@codelipenghui codelipenghui codelipenghui left review comments
@BewareMyPower BewareMyPower BewareMyPower left review comments
@merlimat merlimat merlimat approved these changes
@Technoboy- Technoboy- Awaiting requested review from Technoboy-
@liangyepianzhou liangyepianzhou Awaiting requested review from liangyepianzhou

Uh oh!

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

Assignees

@poorbarcode poorbarcode

Labels

category/reliability The function does not work properly in certain specific environments or failures. e.g. data lost cherry-picked/branch-4.0 cherry-picked/branch-4.2 cherry-picked/branch-5.0 doc-not-needed Your PR changes do not impact docs release/4.0.15 release/4.2.6 release/5.0.2 triage/lhotari/important lhotari's triaging label for important issues or PRs type/bug The PR fixed a bug or issue reported a bug

Projects

Apache Pulsar / Key_Shared and Acknowledgement reliability and usability improvements
Status: Done

Milestone

5.1.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

6 participants

@poorbarcode @lhotari @merlimat @codelipenghui @BewareMyPower @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.