diff --git a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java index 6e4a6090c50be..f332e177105f3 100644 --- a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java +++ b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java @@ -1277,7 +1277,8 @@ public synchronized void updateLedgersIdsComplete(Stat stat) { synchronized void ledgerClosed(final LedgerHandle lh) { final State state = STATE_UPDATER.get(this); - if (state == State.ClosingLedger || state == State.LedgerOpened) { + LedgerHandle currentLedger = this.currentLedger; + if (currentLedger == lh && (state == State.ClosingLedger || state == State.LedgerOpened)) { STATE_UPDATER.set(this, State.ClosedLedger); } else if (state == State.Closed) { // The managed ledger was closed during the write operation