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
commented
Jan 18, 2024
•
edited by merlimat
Loading
Uh oh!
There was an error while loading. Please reload this page.
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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…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
…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
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
|
@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
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Oct 23, 2026
This was referenced Nov 21, 2026
Reviewers
merlimat
merlimat approved these changes
Technoboy-
Awaiting requested review from Technoboy-
Uh oh!
There was an error while loading. Please reload this page.
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|