Skip to content

[Bug] Cannot read field mbean because finalML is null #24410 #24411

Closed

Description

@gaozhangmin

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

version: 3.3.6

Issue Description

I noticed that PR #14606 attempted to fix this issue but was closed with the note that it had already been addressed in PR #12103. However, after checking the code in Pulsar 3.3.6, I can confirm that the fix from PR #12103 is present, yet the issue still persists. This suggests that the previous fix may not have fully resolved the problem.

Error messages


Reproducing the issue

It's hard to reproduce it

Additional information

Image

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Activity

  1. added
    type/bug
    on Jun 16, 2025
  2. lhotari commented on Jun 19, 2025

    @lhotari
    Member

    I noticed that PR #14606 attempted to fix this issue but was closed with the note that it had already been addressed in PR #12103. However, after checking the code in Pulsar 3.3.6, I can confirm that the fix from PR #12103 is present, yet the issue still persists. This suggests that the previous fix may not have fully resolved the problem.

    Your case is different than #14606 or #12103.

    void handleAddFailure(final LedgerHandle lh) {
    // If we get a write error, we will try to create a new ledger and re-submit the pending writes. If the
    // ledger creation fails (persistent bk failure, another instance owning the ML, ...), then the writes will
    // be marked as failed.
    ManagedLedgerImpl finalMl = this.ml;
    finalMl.mbean.recordAddEntryError();
    finalMl.getExecutor().execute(() -> {
    // Force the creation of a new ledger. Doing it in a background thread to avoid acquiring ML lock
    // from a BK callback.
    finalMl.ledgerClosed(lh);
    });
    }

    In your case, the NPE happens on line 339, before the lambda code block that is executed within the executor.

  3. lhotari commented on Jun 19, 2025

    @lhotari
    Member

    @gaozhangmin Have you configured managedLedgerAddEntryTimeoutSeconds to some value? If it's non-zero, it's possible that this is a bug in the managedLedgerAddEntryTimeoutSeconds feature. It seems that race conditions are possible which could lead to the NPE that you are seeing.

  4. gaozhangmin commented on Jun 20, 2025

    @gaozhangmin
    ContributorAuthor

    @gaozhangmin Have you configured managedLedgerAddEntryTimeoutSeconds to some value? If it's non-zero, it's possible that this is a bug in the managedLedgerAddEntryTimeoutSeconds feature. It seems that race conditions are possible which could lead to the NPE that you are seeing.

    managedLedgerAddEntryTimeoutSeconds was configured in my case, i need some time, since it's hard to reproduce

  5. merlimat commented on Oct 24, 2026

    @merlimat
    Contributor

    Thanks @gaozhangmin for the report. This is the race @lhotari suspected in the managedLedgerAddEntryTimeoutSeconds check. The periodic check ran on a scheduler thread and could call handleAddFailure on an OpAddEntry that had just completed and been recycled, which leaves ml null. #27056 now runs the check on the managed ledger executor, where adds complete and get recycled, so it can't see a recycled op. It also guards the periodic task, so an exception can't cancel it. Closing as fixed. If it still happens on a currently supported release that includes that change, please reopen.

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

    area/MLtype/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions