This is an automated email from the ASF dual-hosted git repository.

chia7712 pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/trunk by this push:
     new e7317b37bf4 KAFKA-17269 Fix ConcurrentModificationException caused by 
NioEchoServer.closeNewChannels (#16817)
e7317b37bf4 is described below

commit e7317b37bf4a3ea5beaeb22a9b0707bdb16ebee7
Author: bboyleonp666 <[email protected]>
AuthorDate: Fri Aug 9 03:24:59 2024 +0800

    KAFKA-17269 Fix ConcurrentModificationException caused by 
NioEchoServer.closeNewChannels (#16817)
    
    Reviewers: Chia-Ping Tsai <[email protected]>
---
 .../org/apache/kafka/common/network/NioEchoServer.java   | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git 
a/clients/src/test/java/org/apache/kafka/common/network/NioEchoServer.java 
b/clients/src/test/java/org/apache/kafka/common/network/NioEchoServer.java
index 2509c0a1f8b..80cdc56f107 100644
--- a/clients/src/test/java/org/apache/kafka/common/network/NioEchoServer.java
+++ b/clients/src/test/java/org/apache/kafka/common/network/NioEchoServer.java
@@ -356,17 +356,21 @@ public class NioEchoServer extends Thread {
     }
 
     public void closeSocketChannels() throws IOException {
-        for (SocketChannel channel : socketChannels) {
-            channel.close();
+        synchronized (socketChannels) {
+            for (SocketChannel channel : socketChannels) {
+                channel.close();
+            }
+            socketChannels.clear();
         }
-        socketChannels.clear();
     }
 
     public void closeNewChannels() throws IOException {
-        for (SocketChannel channel : newChannels) {
-            channel.close();
+        synchronized (newChannels) {
+            for (SocketChannel channel : newChannels) {
+                channel.close();
+            }
+            newChannels.clear();
         }
-        newChannels.clear();
     }
 
     public void close() throws IOException, InterruptedException {

Reply via email to