Repository navigation
[fix][ml] Serialize a cursor's reused position info under its monitor - #26944
Merged
merlimat merged 1 commit intoOct 16, 2026
Merged
Conversation
ManagedCursorImpl.persistPositionToLedger builds and serializes a cursor's position with one reused PositionInfo per cursor. A cursor's close persists its position on the closing thread, which can overlap with a mark-delete persisting on another thread, since the close path doesn't take the pendingMarkDeleteOps monitor that orders the mark-deletes. One could clear or change the position info while the other built or serialized it, writing a wrong position to the cursor ledger or failing with an exception before the entry was added. Fill and serialize the position info under its monitor. The cursor's state that goes into it is read before, under the cursor's lock, so that no lock is taken while the monitor is held. Fixes apache#26943 Assisted-by: Claude Code (claude-opus-5-5)
lhotari
requested review from
Technoboy-,
codelipenghui,
dao-jun,
merlimat and
nodece
October 16, 2026 14:07
void-ptr974
approved these changes
Oct 16, 2026
void-ptr974
left a comment
Contributor
There was a problem hiding this comment.
LGTM. The synchronization scope looks appropriate, and the test covers the reported race. Thanks for the clear and focused fix.
merlimat
approved these changes
Oct 16, 2026
2 of 3 tasks
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.
Fixes #26943
Motivation
ManagedCursorImpl.persistPositionToLedgerbuilds and serializes a cursor's position with one reusedPositionInfoper cursor (reusablePositionInfo), without synchronization. Two persists of the same cursor can run at the same time: a cursor's close persists its position (asyncClose→persistPositionWhenClosing) on the closing thread, and that can overlap with a mark-delete persisting (internalMarkDelete) on another thread, since the close path doesn't take thependingMarkDeleteOpsmonitor that orders the mark-deletes.One persist can then clear or change the position info while the other builds or serializes it. The result is either a wrong position written to the cursor ledger, or an exception before the entry is added, so that the persist's callback never completes:
or, when the position has properties:
Modifications
serializePositionInfo.Verifying this change
ManagedCursorPersistPositionConcurrencyTestpersists 20,000 positions from each of two threads with the same cursor and a mocked ledger handle, each thread with its own position and properties. It checks that no persist fails, that every written position info is one thread's position with that thread's properties, and that the written positions are exactly the persisted ones, so no persist wrote another's. Without the change, it fails with theNullPointerExceptions above. With it, it passes.ManagedCursorTest(216) andManagedCursorIndividualDeletedMessagesTestpass.Does this pull request potentially affect one of the following parts:
This change was developed with the assistance of Claude Code.