Skip to content

[Bug][ml] Closing a cursor can fail the same waiting read twice and make pendingReadOps negative #27786

Backlog

Description

@void-ptr974

Search before reporting

  • 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

  1. Set ManagedLedgerConfig.setNewEntriesCheckDelayInMillis(400) and open an empty durable cursor.
  2. Call cursor.asyncReadEntriesOrWait(1, callback, null, PositionFactory.LATEST) with a callback that records each invocation.
  3. 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

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Activity

  1. HimanshuJha-2005 commented on Nov 29, 2026

    @HimanshuJha-2005
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions