diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerHandle.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerHandle.java index 20105a0c1a1..c61f1693a68 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerHandle.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerHandle.java @@ -1836,7 +1836,11 @@ void sendAddSuccessCallbacks() { return; } - pendingAddOps.remove(); + if (!pendingAddOps.remove(pendingAddOp)) { + // If the remove operation fails, it means the element has already been removed by another thread. + // We should continue to the next iteration to process the next element. + continue; + } explicitLacFlushPolicy.updatePiggyBackedLac(lastAddConfirmed); pendingAddsSequenceHead = pendingAddOp.entryId; if (!writeFlags.contains(WriteFlag.DEFERRED_SYNC)) {