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] Fix stale batch ACKs causing skipped messages after seek by void-ptr974 · Pull Request #27067 · apache/pulsar

Conversation

@void-ptr974

@void-ptr974 void-ptr974 commented Oct 23, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Motivation

With batch-index ACKs and grouping enabled, a partial ACK can survive a successful seek. For a batch [0, 1], ACKing only index 0 leaves a bitmap in pendingIndividualBatchIndexAcks. During seek, the broker disconnects the consumer before resetting its cursor. If the seek success response arrives while the consumer has no subscribed connection, flush() returns and flushAndClean() omits that bitmap.

The stale ACK can suppress index 0 locally or be flushed after reconnection and applied to the broker's reset cursor, causing incomplete replay despite a successful seek. A delayed write failure can also restore an old ACK snapshot after cleanup, so clearing the map alone is insufficient.

The execution sources are:

  • A — ACK: the application or message-listener caller.
  • F — flush: the grouping event loop, an ACK-threshold caller, or the subscription-success callback.
  • S — cleanup: the seek-success continuation or seek-related reconnect cleanup before binding the new connection.
  • W — restore: the channel write-failure listener on the non-receipt path.

These are execution roles; they can share threads. A write result can arrive after cleanup even when individual callbacks run serially.

Pending ACK surviving seek, before the fix:

Step Execution State / user-visible result
1 A receives [0, 1] and ACKs index 0 The partial-batch bitmap waits for flush.
2 S handles seek success while disconnected and cleans up flush() returns; the batch-index map is not cleared. Seek-related reconnect cleanup also leaves it behind.
3 Subscription succeeds; F flushes the stale ACK; replay starts after the broker applies it The application receives only [1]. Clearing the bitmap prevents this stale ACK from affecting replay.

The broker regression pauses delivery through reconnect and flush, waits for a subsequent broker response, and then resumes. The no-ACK control receives [0, 1]; the partial-ACK case receives only [1] before the fix.

Delayed write failure crossing cleanup:

Here g0/g1 are local ACK cleanup generations, not protocol consumer epochs.

Step F / W: flush and completion S / A: cleanup and application Required result
1 Drain old ACKs into snapshot g0; submit the write The callback retains the snapshot even though pending is empty.
2 Write result remains pending Clear pending state and advance to g1 Old snapshots become invalid.
3 Record a new ACK from replay Preserve the new ACK.
4 Old write fails and attempts to restore g0 Reject g0 != g1; do not reinsert or merge old ACKs.

Modifications

  • Clear batch-index ACKs together with cumulative and whole-entry individual ACKs.
  • Advance ackGeneration on cleanup and reject failed-write restoration from an older generation. Ordinary reconnects retain ACK retry behavior.
  • Protect generation capture plus snapshot extraction, cleanup, and generation check plus restoration with pendingAcksLock.
  • Keep network writes and future completion outside this monitor. ACK insertion and duplicate checks do not acquire it.

Generation capture and extraction must be atomic with cleanup: otherwise a flush could read g0, then drain a new ACK added after cleanup advances to g1, and incorrectly reject that new ACK's restoration.

This protects pending state and failed-write restoration; it does not retract ACKs already submitted to transport or globally order every application ACK call against seek.

Verifying this change

  • Make sure that the change passes the CI checks.

Local verification passed:

  • 41 client test invocations: AcknowledgementsGroupingTrackerTest, AcknowledgmentsGroupingFlushesTest, and ConsumerImplTest.testSeekAsyncInternal. Coverage includes disconnected/Connecting cleanup, ACK receipt settings, delayed legacy/multi-message write failures, and ordinary reconnect controls.
  • 2 real-broker invocations: ConsumerSeekBatchIndexAckTest, with and without the partial ACK. A long grouping interval and asynchronous reconnect gate make the failing sequence deterministic.
  • Repository-wide ./gradlew quickCheck.

An expanded ConsumerImplTest run hit timeouts in testChunkedMessageCountRaceBetweenReceiveAndExpiry and testClearIncomingMessagesConcurrentWithEnqueueAndReceive and was stopped. The focused tests above subsequently passed.

Does this pull request potentially affect one of the following parts:

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Adds synchronization around flush snapshots, cleanup, and restoration without changing executor assignments.

Sorry, something went wrong.

Uh oh!

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

All reactions
@void-ptr974
[fix][client] Fix stale batch ACKs causing skipped messages after seek
4979f2b
Assisted-by: OpenAI Codex
@codelipenghui codelipenghui assigned void-ptr974 Oct 23, 2026
@codelipenghui codelipenghui added this to the 5.1.0 milestone Oct 23, 2026
codelipenghui
codelipenghui approved these changes Oct 23, 2026
View reviewed changes
@merlimat
merlimat merged commit 73f70bc into apache:master Oct 23, 2026
44 of 45 checks passed

Uh oh!

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

lhotari pushed a commit that referenced this pull request Oct 26, 2026
@void-ptr974 @lhotari
[fix][client] Fix stale batch ACKs causing skipped messages after seek (
f0e9bfd
#27067)

(cherry picked from commit 73f70bc)
@lhotari lhotari added release/5.0.2 cherry-picked/branch-5.0 labels Oct 26, 2026
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
@lhotari lhotari added cherry-picked/branch-4.2 release/4.2.6 cherry-picked/branch-4.0 release/4.0.15 labels Nov 21, 2026
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@void-ptr974 @lhotari
[fix][client] Fix stale batch ACKs causing skipped messages after seek (
27418a9
apache#27067)

(cherry picked from commit 73f70bc)
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@void-ptr974 @lhotari
[fix][client] Fix stale batch ACKs causing skipped messages after seek (
cae9348
apache#27067)

(cherry picked from commit 73f70bc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@codelipenghui codelipenghui codelipenghui approved these changes

Uh oh!

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

Assignees

@void-ptr974 void-ptr974

Labels

cherry-picked/branch-4.0 cherry-picked/branch-4.2 cherry-picked/branch-5.0 release/4.0.15 release/4.2.6 release/5.0.2

Projects

None yet

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.

4 participants

@void-ptr974 @codelipenghui @merlimat @lhotari
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.