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][broker] Clear pending read flags when a read fails before the cursor takes ownership by nodece · Pull Request #27059 · apache/pulsar

Conversation

@nodece

@nodece nodece commented Oct 23, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

Related to #26454

Motivation

A Shared (multiple-consumers) subscription can stall forever when a synchronous Throwable escapes
readMoreEntries() after havePendingRead/havePendingReplayRead is set but before the read
is submitted to the managed cursor. The exception is only logged by the event-loop executor
(A task raised an exception), no completion callback is ever registered, and nothing clears the
flag: readMoreEntries refuses to run while it is set and checkAndUnblockIfStuck requires
!havePendingRead, leaving a topic unload as the only recovery.

Observed in production on 3.0.14: 10 out of 132 dispatchers were permanently stuck with the
signature havePendingRead=true, waitingReadOp=null, pendingReadOps=0 and a pristine read-failure
backoff (proving readEntriesFailed never ran); the stuck dispatchers clustered around consumer
re-attach batches. Reproduced on a real standalone 3.0.14 broker by injecting a one-shot
OutOfMemoryError while the read was being scheduled:

WARN io.netty.util.concurrent.AbstractEventExecutor - A task raised an exception.
    Task: PersistentDispatcherMultipleConsumers$$Lambda...
java.lang.OutOfMemoryError: ...
    at ...PersistentDispatcherMultipleConsumers.readMoreEntries(...)
    at ...PersistentDispatcherMultipleConsumers.lambda$readMoreEntriesAsync$4(...)
    ...

After the fault, new consumers and new publishes deliver nothing (backlog frozen, msgOutCounter=0);
unload recovers. The same unprotected path exists on this branch and on the 3.0.x / 4.x / 5.0
branches, so a backport is recommended.

Modifications

In PersistentDispatcherMultipleConsumers:

  1. Wrap the normal-read and replay-read scheduling sections - from
    havePendingRead/havePendingReplayRead = true until the read is submitted to the managed
    cursor - in try/catch (Throwable). On failure the flag is cleared and the read is retried with
    backoff instead of being left set forever.
  2. Extract the shared failure handling into handleReadSchedulingFailure(Throwable, ReadType), which
    also cancels a possibly registered wait-read so that the cleared flag cannot leave the cursor
    waiting.
  3. Move the flag reset and onReadEnded to the top of readEntriesFailed, so an exception raised
    later in that callback can no longer strand the flag.

Verifying this change

  • Make sure that the change passes the CI checks.

This change added tests and can be verified as follows:

New PersistentDispatcherMultipleConsumersStuckReadTest (6 tests, following the existing
PersistentDispatcherSingleActiveConsumerStuckReadTest pattern):

  • a read failure callback interrupted mid-way still clears the flag;
  • normal failure handling still registers the tail-wait read again and later messages are delivered;
  • the interrupted failure is recovered by checkAndUnblockIfStuck;
  • a read scheduling failure is retried and the backlog is delivered;
  • a replay scheduling failure is retried and the entry is redelivered;
  • a scheduling failure after the wait-read was registered cancels it and the retry
    re-registers it, after which publishes are delivered.

Verified: on unpatched master testReadSchedulingFailureIsRetriedAndDelivers fails (nothing is
delivered within 10s); with this patch all 6 tests pass. On the real standalone 3.0.14 broker
mentioned above, the fault now turns into a logged Failed to schedule read of messages followed by
a successful retry, and delivery continues.

Sorry, something went wrong.

Uh oh!

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

All reactions
@nodece
[fix][broker] Clear pending read flags when a read fails before the c…
7dc321c
…ursor takes ownership
merlimat
merlimat approved these changes Oct 23, 2026
View reviewed changes
codelipenghui
codelipenghui reviewed Oct 23, 2026
View reviewed changes

@codelipenghui codelipenghui 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.

Thanks for tracking this down. Clearing the flag when a read fails between setting havePendingRead/havePendingReplayRead and handing the read to the cursor fixes a real liveness problem: nothing else ever clears it, and checkAndUnblockIfStuck can't detect it. For failures that happen before the cursor takes the read, the change looks correct to me. I ran the new PersistentDispatcherMultipleConsumersStuckReadTest (4/4 pass) and the existing PersistentDispatcherMultipleConsumersTest (17/17 pass) locally.

My inline comments are mostly about what the catch can and can't guarantee once the cursor has already taken the read, plus two branches that have no tests.

About the description: Fixes #26454 would close the issue, but the 4.0.12 report and the heap-dump report there only match the stuck-state signature, and the reproduction here injects an OOM. Unless the production logs from the time of a stall show the escaped Throwable (e.g. Netty's A task raised an exception from readMoreEntries), I'd suggest Related to #26454 and keeping the issue open.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread .../java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java Resolved

Uh oh!

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

Comment thread .../java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java Resolved

Uh oh!

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

Comment thread .../java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java Resolved

Uh oh!

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

Comment thread ...che/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumersStuckReadTest.java Resolved

Uh oh!

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

@nodece
[fix][broker] Address review: pair read notifications, document best-…
e946315
…effort recovery, extend tests

- Call onReadEnded only when onReadStarted was reached, by passing a
  readStarted flag into handleReadSchedulingFailure: a failure from
  updateMinReplayedPosition no longer notifies an unpaired read end,
  which PersistentStickyKeyDispatcherMultipleConsumers uses to account
  replay reads in flight.
- Document that the recovery is best-effort: the failure may also come
  from inside the managed cursor after it already took over the read,
  where cursor-side state (such as the pending read operations counter)
  can still be left behind until a follow-up fix in the managed ledger.
- Add tests for the replay scheduling failure (redelivery resumes after
  the retry) and for a failure that happens after the wait-read was
  registered (the registered read is cancelled, the retry re-registers
  it and later publishes are delivered), and assert
  cursor.getPendingReadOpsCount() == 0 after recovery.

Assisted-by: Claude Code
@nodece
nodece requested review from codelipenghui and lhotari October 23, 2026 08:23
dao-jun
dao-jun approved these changes Oct 23, 2026
View reviewed changes
void-ptr974
void-ptr974 reviewed Oct 23, 2026
View reviewed changes

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

Thanks for adding the extra regression coverage! All six new tests and the 17 existing dispatcher tests passed locally with retries disabled. I have one small suggestion below to strengthen the wait-read cancellation test.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread ...che/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumersStuckReadTest.java Resolved

Uh oh!

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

codelipenghui
codelipenghui reviewed Oct 23, 2026
View reviewed changes

@codelipenghui codelipenghui 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.

Thanks for the quick update. The production-side changes look good to me: onReadEnded is now paired with onReadStarted, the javadoc calls the recovery best-effort with the cursor-side fix tracked separately, and the description says Related to #26454. I ran PersistentDispatcherMultipleConsumersStuckReadTest locally at e946315 and all 6 tests pass.

Two of the new scheduling-failure tests don't guard the branches they target yet, though. Details inline:

  • the replay test's injected failure never fires;
  • the wait-read test passes without the fix.

testReadSchedulingFailureIsRetriedAndDelivers is currently the only scheduling-failure test that would fail on the unpatched dispatcher.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread ...che/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumersStuckReadTest.java Resolved

Uh oh!

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

Comment thread ...che/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumersStuckReadTest.java Resolved

Uh oh!

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

@merlimat merlimat added this to the 5.1.0 milestone Oct 23, 2026
@merlimat merlimat added release/4.0.15 release/5.0.2 labels Oct 23, 2026
@nodece
nodece requested a review from codelipenghui October 27, 2026 04:18
codelipenghui
codelipenghui approved these changes Oct 27, 2026
View reviewed changes

@codelipenghui codelipenghui 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.

Thanks for addressing the review feedback. Reviewed 6cf6ce8: the replay test now exercises the injected failure and verifies retry scheduling, and the wait-read test verifies cancellation and a second read before publishing. All six focused regression tests passed locally with retries disabled. No remaining actionable findings within the reviewed scope. LGTM.

Sorry, something went wrong.

Uh oh!

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

All reactions
@nodece
nodece requested a review from void-ptr974 October 27, 2026 07:47
@nodece nodece self-assigned this Oct 27, 2026
@nodece
[test][broker] Make the replay and wait-read scheduling failure tests…
6b2ccf0
… fail without the fix

Disable delayed delivery in the fixture so the replay path goes through
asyncReplayEntries, the method the test fails, instead of
asyncReplayEntriesInOrder which bypasses it. Verify the replay failure
handler ran before checking redelivery, and in the wait-read test verify
the registered read was cancelled and a second read scheduled before
publishing, so the delivery cannot come from the original wait-read. Both
tests now fail on the unpatched dispatcher.

Assisted-by: Claude Code
@nodece
nodece force-pushed the fix-26454-phantom-pending-read branch from 6cf6ce8 to 6b2ccf0 Compare October 27, 2026 07:48
void-ptr974
void-ptr974 approved these changes Oct 27, 2026
View reviewed changes
@nodece
nodece merged commit fadf061 into apache:master Oct 27, 2026
43 checks passed

Uh oh!

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

@nodece nodece mentioned this pull request Oct 27, 2026
[fix][ml] Report read and replay failures through callbacks and keep accounting balanced #27130
Merged
1 of 11 tasks
lhotari pushed a commit that referenced this pull request Oct 28, 2026
@nodece @lhotari
[fix][broker] Clear pending read flags when a read fails before the c…
0fc884c
…ursor takes ownership (#27059)

(cherry picked from commit fadf061)
@lhotari lhotari added the cherry-picked/branch-5.0 label Oct 28, 2026
@dlg99 dlg99 mentioned this pull request Oct 30, 2026
[fix][broker] Clear pending read flags when a read fails before the cursor takes ownership OSS#27059 datastax/pulsar#859
Closed
1 task done
@rakshithdatastax rakshithdatastax mentioned this pull request Nov 2, 2026
[fix][broker] Clear pending read flags when a read fails before the cursor takes ownership datastax/pulsar#863
Merged
1 task done
dlg99 added a commit to datastax/pulsar that referenced this pull request Nov 2, 2026
@rakshithdatastax @dlg99
[fix][broker] Clear pending read flags when a read fails before the c…
3c3eac6
…ursor takes ownership (#863)

* [fix][broker] Clear pending read flags when a read fails before the cursor takes ownership OSS#27059

Re-working OSS PR apache#27059 from 4.0
to Luna 3.1
---------

Co-authored-by: Andrey Yegorov <[email protected]>
@nodece nodece mentioned this pull request Nov 5, 2026
[fix][broker][ml] Backport #27059 and #27130: recover from synchronous read-path failures ascentstream/pulsar#108
Closed
5 of 6 tasks
nodece added a commit to ascentstream/pulsar that referenced this pull request Nov 5, 2026
@nodece
[fix][broker] Clear pending read flags when a read fails before the c…
8cbce58
…ursor takes ownership (apache#27059)
nodece added a commit to ascentstream/pulsar that referenced this pull request Nov 5, 2026
@nodece
[fix][broker] Clear pending read flags when a read fails before the c…
a447c14
…ursor takes ownership (apache#27059)
nodece added a commit to ascentstream/pulsar that referenced this pull request Nov 5, 2026
@nodece
[fix][broker] Clear pending read flags when a read fails before the c…
fea36d4
…ursor takes ownership (apache#27059)
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 labels Nov 21, 2026
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@nodece @lhotari
[fix][broker] Clear pending read flags when a read fails before the c…
651dc0e
…ursor takes ownership (apache#27059)

(cherry picked from commit fadf061)
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@nodece @lhotari
[fix][broker] Clear pending read flags when a read fails before the c…
16884c0
…ursor takes ownership (apache#27059)

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

Reviewers

@merlimat merlimat merlimat approved these changes
@codelipenghui codelipenghui codelipenghui approved these changes
@dao-jun dao-jun dao-jun approved these changes
@lhotari lhotari Awaiting requested review from lhotari
+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

@nodece nodece

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.

6 participants

@nodece @merlimat @codelipenghui @dao-jun @void-ptr974 @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.