Copilot commented on code in PR #24725: URL: https://github.com/apache/pulsar/pull/24725#discussion_r2336840102
########## pulsar-client/src/main/java/org/apache/pulsar/client/impl/PersistentAcknowledgmentsGroupingTracker.java: ########## @@ -484,16 +483,15 @@ private void flushAsync(ClientCnx cnx) { } } - if (!pendingIndividualBatchIndexAcks.isEmpty()) { - Iterator<Map.Entry<MessageIdAdv, ConcurrentBitSetRecyclable>> iterator = - pendingIndividualBatchIndexAcks.entrySet().iterator(); - - while (iterator.hasNext()) { - Map.Entry<MessageIdAdv, ConcurrentBitSetRecyclable> entry = iterator.next(); - entriesToAck.add(Triple.of( - entry.getKey().getLedgerId(), entry.getKey().getEntryId(), entry.getValue())); - iterator.remove(); + while (!pendingIndividualBatchIndexAcks.isEmpty()) { + Map.Entry<MessageIdAdv, ConcurrentBitSetRecyclable> entry = + pendingIndividualBatchIndexAcks.pollFirstEntry(); + if (entry == null) { + // The entry has been removed in a different thread Review Comment: The check `!pendingIndividualBatchIndexAcks.isEmpty()` in the while condition creates a race condition. Another thread could remove the last entry between the isEmpty() check and pollFirstEntry() call, causing unnecessary loop iterations. Consider using `while (true)` and relying solely on the null check from `pollFirstEntry()`. ```suggestion while (true) { Map.Entry<MessageIdAdv, ConcurrentBitSetRecyclable> entry = pendingIndividualBatchIndexAcks.pollFirstEntry(); if (entry == null) { ``` -- 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