lianetm commented on code in PR #19917:
URL: https://github.com/apache/kafka/pull/19917#discussion_r2153086039
##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/TopicMetadataRequestManager.java:
##########
@@ -84,16 +84,21 @@ public TopicMetadataRequestManager(final LogContext
context, final Time time, fi
@Override
public NetworkClientDelegate.PollResult poll(final long currentTimeMs) {
// Prune any requests which have timed out
- List<TopicMetadataRequestState> expiredRequests =
inflightRequests.stream()
- .filter(TimedRequestState::isExpired)
- .collect(Collectors.toList());
+ List<TopicMetadataRequestState> expiredRequests = new ArrayList<>();
+
+ for (TopicMetadataRequestState requestState : inflightRequests) {
+ if (requestState.isExpired())
+ expiredRequests.add(requestState);
+ }
+
expiredRequests.forEach(TopicMetadataRequestState::expire);
Review Comment:
> Apparently it's not an error to remove it directly from the collection
while iterating over the collection
Agree it doesn't seem to fail with the tests we have, but still I would
expect it may not be safe to modify the collection from within the loop (and
may lead to ConcurrentModification exception at some point?).
I would say we play safe and use an iterator, makes sense?
--
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]