nodece commented on code in PR #25240:
URL: https://github.com/apache/pulsar/pull/25240#discussion_r3231521977
##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java:
##########
@@ -2052,7 +2076,7 @@ public ManagedLedgerInterceptor
getManagedLedgerInterceptor() {
return managedLedgerInterceptor;
}
- void clearPendingAddEntries(ManagedLedgerException e) {
+ synchronized void clearPendingAddEntries(ManagedLedgerException e) {
Review Comment:
The `synchronized` keyword on `clearPendingAddEntries` also appears
unnecessary, since `pendingAddEntries` is already a concurrent queue.
Additionally, the current `isEmpty()` + `poll()` sequence is not atomic and
may lead to an NPE.
This can be simplified to:
```java
void clearPendingAddEntries(ManagedLedgerException e) {
OpAddEntry op;
while ((op = pendingAddEntries.poll()) != null) {
op.failed(e);
}
}
```
This avoids the race condition between `isEmpty()` and `poll()`.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]