You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug][ml] Closing a cursor can fail the same waiting read twice and make pendingReadOps negative #27786
I searched in the issues and found nothing similar.
Read release policy
I understand that unsupported versions don't get bug fixes. I will attempt to reproduce the issue on a supported version of Pulsar client and Pulsar broker.
User environment
Managed Ledger Java test with mock BookKeeper. The reproduction used ManagedCursorImpl from master at a602f161344. It calls the cursor API directly.
Issue Description
Closing an empty durable cursor can invoke the failure callback twice for a single asyncReadEntriesOrWait request. The callback returns normally both times. The pending-read count then drops from zero to -1.
The caller should receive one close failure. The count should stay at zero because the cursor was waiting for the first entry and had not submitted a ledger read.
Error messages
OBSERVED callback=1 cause=Cursor is closing
OBSERVED callback=2 cause=Cursor was already closed
OBSERVED callbacks=2 pendingReadOps=-1
Reproducing the issue
Set ManagedLedgerConfig.setNewEntriesCheckDelayInMillis(400) and open an empty durable cursor.
Call cursor.asyncReadEntriesOrWait(1, callback, null, PositionFactory.LATEST) with a callback that records each invocation.
Call cursor.close() before the 400 ms check runs. Allow the delayed check to execute, then inspect the recorded failures and cursor.getPendingReadOpsCount().
Additional information
closeWaitingCursor claims the waiting read and calls OpReadEntry.readEntriesFailed, which decrements the count. The scheduled check still holds the original callback and invokes it again when it sees the closed cursor. We found this while testing #27693 and reproduced it on master without a seek. Close path · Delayed check
Hi @void-ptr974, are you currently working on a PR for this? If not, I'd be happy to take it up, fix the double callback and \pendingReadOps\ decrement in \ManagedCursorImpl, and add a regression test for this sequence.
Activity
HimanshuJha-2005 commentedon Nov 29, 2026
Hi @void-ptr974, are you currently working on a PR for this? If not, I'd be happy to take it up, fix the double callback and \pendingReadOps\ decrement in \ManagedCursorImpl, and add a regression test for this sequence.