chia7712 commented on code in PR #16753:
URL: https://github.com/apache/kafka/pull/16753#discussion_r1703070893


##########
clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java:
##########
@@ -1196,16 +1196,31 @@ private long maybeDrainPendingCalls(long now) {
             long pollTimeout = Long.MAX_VALUE;
             log.trace("Trying to choose nodes for {} at {}", pendingCalls, 
now);
 
-            Iterator<Call> pendingIter = pendingCalls.iterator();
-            while (pendingIter.hasNext()) {
-                Call call = pendingIter.next();
+            List<Call> toRemove = new ArrayList<>();
+            // Using for-loop instead of iterator to avoid 
ConcurrentModificationException with following sequence:
+            // 1. In maybeDrainPendingCalls, pendingCalls.iterator() create a 
iterator.
+            // 2. In maybeDrainPendingCall, call.nodeProvider.provide() throws 
UnsupportedVersionException error.
+            // 3. In call.fail, runnable.pendingCalls.add modify the 
pendingCalls list.
+            // Using pendingCalls.size() to get the list size before the 
for-loop to avoid infinite loop.
+            // If call.fail keeps adding the call to pendingCalls,
+            // the loop like for (int i = 0; i < pendingCalls.size(); i++) 
can't stop.

Review Comment:
   oh, you are right. The re-added calls will encounter the same error again. 



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