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][ml] Release terminal read ownership before notifying callbacks by codelipenghui · Pull Request #27381 · apache/pulsar

Conversation

@codelipenghui

@codelipenghui codelipenghui commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Motivation

When a waiting cursor reaches a terminated ledger's end, its EOF callback currently runs without releasing the waiting-read reservation. A subsequent or reentrant read can therefore fail with ConcurrentWaitCallbackException instead of EOF. If the observer throws, the outer catch can deliver a second failure for the same read.

Modifications

Claim only the original waiting operation and its identity, remove its waiting registration under the existing registration lock, and recycle it before notifying the observer. Keep the callback outside the lock and isolate observer failures.

This is a wait-only operation: it never incremented the pending-read count, so the fix does not decrement that count or alter the existing read/replay accounting.

Verifying this change

Tests-only execution on unpatched Apache master a72adf733ead20ba4b19a76222b698f315073ecf reproduced 4 failures, covering a second EOF read, reentry, observer failure and concurrent registration.

With the fix, 33 cases passed, with no failures/errors/skips and retries disabled:

  • ManagedCursorTerminalReadTest
  • ManagedLedgerReadPathSyncFailureTest
  • ManagedLedgerTerminationTest

quickCheck and git diff --check passed.

./gradlew :managed-ledger:test \
  --tests ManagedCursorTerminalReadTest \
  --tests ManagedLedgerReadPathSyncFailureTest \
  --tests ManagedLedgerTerminationTest \
  -PtestRetryCount=0 -PtestMaxParallelForks=1 -PtestJavaVersion=21
./gradlew quickCheck

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

Threading: coordinate terminal completion and replacement waiting-read registration using the existing lock; callbacks remain outside it.

Sorry, something went wrong.

Uh oh!

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

All reactions
codelipenghui and others added 2 commits November 5, 2026 09:42
@codelipenghui
[fix][ml] Release terminal read ownership before notifying callbacks
1eac167
Release only the exact waiting read and registration before terminal callbacks. Recycle wait-only operations without changing pending-read accounting, and isolate observer failures from duplicate completion.

Four tests-only cases fail on unpatched master; all33 scoped cases and quickCheck pass with retries disabled.

Assisted-by: OpenAI Codex
@codelipenghui @claude
[fix][ml] Claim waiting reads by a never-reused registration token
02eec3f
A delayed check claimed its waiting read with getAndUpdate, comparing the
pooled OpReadEntry reference and its id in the update function. The
compare-and-set only compares the reference, so if the read was cancelled,
recycled and registered again with the same instance between the id check
and the CAS, the stale check cleared the replacement's registration and the
replacement never got a callback.

Register each waiting read with a new WaitingRead token and claim it with a
single compareAndSet on that token, in both the terminal and the
entries-available paths. A stale check can no longer match a later
registration of the same OpReadEntry.

Add a regression test that forces the pool to reuse the cancelled read's
OpReadEntry for the replacement and runs the stale check against it.

Assisted-by: Claude Code (claude-opus-5-5)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@codelipenghui codelipenghui self-assigned this Nov 7, 2026
@codelipenghui codelipenghui added type/bug The PR fixed a bug or issue reported a bug release/4.2.6 release/4.0.15 release/5.0.2 labels Nov 7, 2026
@codelipenghui codelipenghui added this to the 5.1.0 milestone Nov 7, 2026
@codelipenghui
codelipenghui marked this pull request as ready for review November 7, 2026 07:26
@codelipenghui
codelipenghui requested review from Denovo1998, lhotari, merlimat and poorbarcode November 9, 2026 17:13
void-ptr974
void-ptr974 approved these changes Nov 16, 2026
View reviewed changes
@void-ptr974

void-ptr974 commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Thanks for the fix and the regression coverage! The unique WaitingRead token makes ownership clearer, and releasing the operation before invoking the callback handles reentrant reads nicely.

One maintainability improvement would be to make wait-only completion consistent between EOF and cursor close. EOF correctly leaves pendingReadOps unchanged, while close still calls OpReadEntry.readEntriesFailed(), which decrements a counter that the waiting request never incremented.

A shared completion path for wait-only requests could centralize deregistration, recycling, and callback handling without changing the read counter. Actual reads would retain their existing counted completion path. This would reduce duplicated cleanup logic and help prevent the two paths from drifting apart.

This can be a follow-up to keep this PR focused.

All reactions

Sorry, something went wrong.

Uh oh!

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

Denovo1998
Denovo1998 approved these changes Nov 17, 2026
View reviewed changes
poorbarcode
poorbarcode approved these changes Nov 17, 2026
View reviewed changes

@poorbarcode poorbarcode left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

NIT — The impact looks limited, but I’d suggest stopping the dispatcher’s automatic read retry once it has notified consumers that a terminated topic has no backlog. To reproduce, terminate an empty non-partitioned topic, then subscribe with an Exclusive consumer and a MessageListener and leave it connected. After the default 15-second backoff, the dispatcher reads again, gets EOF, and sends a second notification to the same listener. Extending the wait in SimpleProducerConsumerTest.testReachedEndOfTopic from 1 to 27 seconds reproduces the duplicate reachedEndOfTopic() call.

Sorry, something went wrong.

Uh oh!

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

All reactions
@codelipenghui
codelipenghui merged commit 2a4654d into apache:master Nov 17, 2026
52 of 55 checks passed

Uh oh!

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

lhotari pushed a commit that referenced this pull request Nov 17, 2026
@codelipenghui @claude @lhotari
[fix][ml] Release terminal read ownership before notifying callbacks (#…
a9567f4
…27381)

Co-authored-by: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 2a4654d)
@lhotari lhotari added the cherry-picked/branch-5.0 label Nov 17, 2026
@poorbarcode poorbarcode mentioned this pull request Nov 18, 2026
[fix][broker] Stop read retries for drained terminated topics #27661
Open
1 of 10 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
@lhotari lhotari added cherry-picked/branch-4.2 cherry-picked/branch-4.0 labels Nov 21, 2026
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@codelipenghui @claude @lhotari
[fix][ml] Release terminal read ownership before notifying callbacks (a…
f58cf69
…pache#27381)

Co-authored-by: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 2a4654d)
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@codelipenghui @claude @lhotari
[fix][ml] Release terminal read ownership before notifying callbacks (a…
69e13d5
…pache#27381)

Co-authored-by: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 2a4654d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@poorbarcode poorbarcode poorbarcode approved these changes
@Denovo1998 Denovo1998 Denovo1998 approved these changes
@lhotari lhotari Awaiting requested review from lhotari
@merlimat merlimat Awaiting requested review from merlimat
+1 more reviewer
@void-ptr974 void-ptr974 void-ptr974 approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

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

Assignees

@codelipenghui codelipenghui

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 type/bug The PR fixed a bug or issue reported a bug

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.

5 participants

@codelipenghui @void-ptr974 @poorbarcode @Denovo1998 @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.