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] Run the add-entry timeout check on the managed ledger executor by lhotari · Pull Request #27056 · apache/pulsar

Conversation

@lhotari

@lhotari lhotari commented Oct 22, 2026

Copy link
Copy Markdown
Member

Motivation

The managed ledger's add-entry timeout check (checkAddTimeout) runs periodically on a scheduler thread. It peeks the pooled OpAddEntry at the head of pendingAddEntries, reads its lastInitTime, ledger and entryId, and then calls handleAddFailure.

Meanwhile the add completes on the managed ledger executor: OpAddEntry.run() polls the op from the queue, completes it and recycles it. Recycling nulls ml and ledger, and the Netty Recycler can then hand the same object to another add, possibly one for another managed ledger. The window is narrow, but it is exactly when the timeout matters: a slow bookie add completing around the deadline. In that window the check can:

  • fail with a NullPointerException in handleAddFailure (this.ml is null). The task is scheduled with scheduleAtFixedRate without an exception guard, so the exception cancels all later runs and the managed ledger silently loses add-timeout detection;
  • or apply the timeout to an op that has already completed or has been reused by another add.

When the bug was introduced: the check has run on the scheduler thread, peeking pendingAddEntries, since the add-entry timeout was added in #3347 (a704afd, 2019-01-15) and #4111 (5e96a9c, 2019-04-23). OpAddEntry.recycle() has nulled ml since the initial import. The exception guard on the periodic task was lost in #20060 (bafecb2, 2023-04-10, "Removed usages of SafeRun"). The same code is on branch-3.0, branch-3.3, branch-4.0, branch-4.1 and branch-4.2, so this is long-standing rather than a recent regression. On those branches the periodic task also runs the read-timeout check, so an exception there stops read-timeout detection for that managed ledger as well.

Modifications

  • The periodic task now hands the check over to the managed ledger executor, where adds complete and get recycled. The check is serialized with those completions and can never read a recycled op. checkAddTimeout itself is unchanged.
  • Both the periodic task and the check are wrapped with catchingAndLoggingThrowables, the helper already used for other periodic managed-ledger tasks, so an exception can't cancel the periodic task.

Verifying this change

  • Make sure that the change passes the CI checks.

This change added tests and can be verified as follows:

  • Added ManagedLedgerTest.testAddTimeoutCheckRunsAfterQueuedAddCompletion. An add is made older than the timeout, and its successful completion is queued on a blocked managed ledger executor. Triggering the timeout check must not apply the timeout. Without the fix, the check applies the timeout to the completed add and the ledger gets switched. The existing add-timeout tests (testManagedLedgerWithAddEntryTimeOut, testAddEntryResponseTimeout, testLedgerInfoMetaCorrectIfAddEntryTimeOut) still pass.

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

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
    • The periodic add-entry timeout check now runs on the managed ledger's executor instead of the scheduler thread.
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Sorry, something went wrong.

Uh oh!

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

All reactions
@lhotari
[fix][ml] Run the add-entry timeout check on the managed ledger executor
20e8d62
The periodic add-entry timeout check ran on the scheduler thread and read the
pooled OpAddEntry at the head of the pending queue while the managed ledger
executor could complete and recycle it. It could then fail with an NPE, which
cancels the periodic check for good, or apply the timeout to an op reused by
another add. Hop to the managed ledger executor, where the adds complete, and
keep any exception from cancelling the periodic task.

Assisted-by: Claude Code (claude-opus-5-5)
@lhotari
lhotari requested review from Technoboy-, codelipenghui, dao-jun, merlimat and nodece October 22, 2026 21:46
merlimat
merlimat approved these changes Oct 22, 2026
View reviewed changes
@merlimat merlimat added this to the 5.1.0 milestone Oct 22, 2026
@merlimat merlimat added release/4.0.15 release/5.0.2 labels Oct 22, 2026
@merlimat
merlimat merged commit aeaf47e into apache:master Oct 22, 2026
44 checks passed

Uh oh!

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

lhotari added a commit that referenced this pull request Oct 23, 2026
@lhotari
[fix][ml] Run the add-entry timeout check on the managed ledger execu…
ab530fa
…tor (#27056)

(cherry picked from commit aeaf47e)
@lhotari lhotari added the cherry-picked/branch-5.0 label Oct 23, 2026
@merlimat merlimat mentioned this pull request Oct 24, 2026
[Bug] Cannot read field mbean because finalML is null #24410 #24411
Closed
3 tasks done
@Denovo1998 Denovo1998 mentioned this pull request Oct 25, 2026
[fix][ml] Fix NPE in OpAddEntry.handleAddFailure when OpAddEntry is already recycled #26899
Closed
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
@lhotari
[fix][ml] Run the add-entry timeout check on the managed ledger execu…
d27ab96
…tor (apache#27056)

(cherry picked from commit aeaf47e)
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@lhotari
[fix][ml] Run the add-entry timeout check on the managed ledger execu…
4af6b6c
…tor (apache#27056)

(cherry picked from commit aeaf47e)
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
@nodece nodece Awaiting requested review from nodece
@dao-jun dao-jun Awaiting requested review from dao-jun
@Technoboy- Technoboy- Awaiting requested review from Technoboy-
@codelipenghui codelipenghui Awaiting requested review from codelipenghui

Uh oh!

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

Assignees

No one assigned

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.

2 participants

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