lhotari commented on code in PR #24522: URL: https://github.com/apache/pulsar/pull/24522#discussion_r2210015881
########## managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/OpAddEntry.java: ########## @@ -143,10 +152,13 @@ public void initiate() { payloadProcessorHandle = ml.getManagedLedgerInterceptor() .processPayloadBeforeLedgerWrite(this.getCtx(), duplicateBuffer); } catch (Exception e) { + ManagedLedgerException mle = new ManagedLedgerException.ManagedLedgerInterceptException(e); + ml.exceptionBeforeWrite = mle; ml.pendingAddEntries.remove(this); ReferenceCountUtil.safeRelease(duplicateBuffer); log.error("[{}] Error processing payload before ledger write", ml.getName(), e); - this.failed(new ManagedLedgerException.ManagedLedgerInterceptException(e)); + this.failed(mle); + recycle(); Review Comment: Don't recycle in exceptional execution path ########## managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/OpAddEntry.java: ########## @@ -133,6 +133,15 @@ public void setCloseWhenDone(boolean closeWhenDone) { public void initiate() { if (STATE_UPDATER.compareAndSet(OpAddEntry.this, State.OPEN, State.INITIATED)) { ByteBuf duplicateBuffer = data.retainedDuplicate(); + // Fail the add operation if the managed ledger is in a state that prevents adding entries. + ManagedLedgerException exbw = ml.exceptionBeforeWrite; + if (exbw != null) { + ml.pendingAddEntries.remove(this); + this.failed(exbw); + ReferenceCountUtil.safeRelease(data); + recycle(); Review Comment: It's better to avoid recycling in exceptional paths. This can help avoid hard-to-reproduce issues. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pulsar.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org