FrankYang0529 commented on code in PR #16753:
URL: https://github.com/apache/kafka/pull/16753#discussion_r1703070720
##########
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:
I think the loop can't stop, please see
https://www.programiz.com/online-compiler/60n1G5xTAUTJO.
Yes, we don't want to verify re-enqueue call.
##########
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.
Review Comment:
Updated it. Thanks.
--
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]