dlg99 commented on code in PR #25207:
URL: https://github.com/apache/pulsar/pull/25207#discussion_r2760532935


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerImpl.java:
##########
@@ -2298,11 +2304,16 @@ public void run(Timeout timeout) throws Exception {
      * This fails and clears the pending messages with the given exception. 
This method should be called from within the
      * ProducerImpl object mutex.
      */
-    private synchronized void failPendingMessages(ClientCnx cnx, 
PulsarClientException ex) {
+    @VisibleForTesting
+    synchronized void failPendingMessages(ClientCnx cnx, PulsarClientException 
ex) {
         if (cnx == null) {
             final AtomicInteger releaseCount = new AtomicInteger();
             final boolean batchMessagingEnabled = isBatchMessagingEnabled();
-            pendingMessages.forEach(op -> {
+            final ArrayList<OpSendMsg> failingMessages = new 
ArrayList<>(pendingMessages.size());

Review Comment:
   how many pending messages there can be? is this a good idea to allocate new 
ArrayList all the time?
   method is synchronized, so it should be safe to create a static ArrayList of 
size e.g. 100 and drain min(100, pendingMessages.size()) and process and repeat 
until pendingMessages.size() == 0 



-- 
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]

Reply via email to