Repository navigation
[fix][ml] Run the add-entry timeout check on the managed ledger executor - #27056
Merged
Merged
Conversation
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
requested review from
Technoboy-,
codelipenghui,
dao-jun,
merlimat and
nodece
October 22, 2026 21:46
merlimat
approved these changes
Oct 22, 2026
3 tasks done
poorbarcode
pushed a commit
to poorbarcode/pulsar
that referenced
this pull request
Nov 26, 2026
…tor (apache#27056) (cherry picked from commit aeaf47e)
poorbarcode
pushed a commit
to poorbarcode/pulsar
that referenced
this pull request
Nov 26, 2026
…tor (apache#27056) (cherry picked from commit aeaf47e)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
The managed ledger's add-entry timeout check (
checkAddTimeout) runs periodically on a scheduler thread. It peeks the pooledOpAddEntryat the head ofpendingAddEntries, reads itslastInitTime,ledgerandentryId, and then callshandleAddFailure.Meanwhile the add completes on the managed ledger executor:
OpAddEntry.run()polls the op from the queue, completes it and recycles it. Recycling nullsmlandledger, 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:NullPointerExceptioninhandleAddFailure(this.mlis null). The task is scheduled withscheduleAtFixedRatewithout an exception guard, so the exception cancels all later runs and the managed ledger silently loses add-timeout detection;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 nulledmlsince 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 onbranch-3.0,branch-3.3,branch-4.0,branch-4.1andbranch-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
checkAddTimeoutitself is unchanged.catchingAndLoggingThrowables, the helper already used for other periodic managed-ledger tasks, so an exception can't cancel the periodic task.Verifying this change
This change added tests and can be verified as follows:
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