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


##########
clients/src/test/java/org/apache/kafka/common/network/SelectorTest.java:
##########
@@ -831,13 +833,19 @@ public void 
testInboundConnectionsCountInConnectionCreationMetric() throws Excep
             for (int i = 0; i < conns; i++) {
                 Thread sender = createSender(serverAddress, randomPayload(1));
                 sender.start();
-                SocketChannel channel = ss.accept();
-                channel.configureBlocking(false);
-
-                selector.register(Integer.toString(i), channel);
+                threads.add(sender);
+                try (SocketChannel channel = ss.accept()) {

Review Comment:
   if the exception is produced here, the following "join" won't be executed. 
Maybe we can use try-finally? for example:
   ```java
           try (ServerSocketChannel ss = ServerSocketChannel.open()) {
               ss.bind(new InetSocketAddress(0));
               InetSocketAddress serverAddress = (InetSocketAddress) 
ss.getLocalAddress();
   
               for (int i = 0; i < conns; i++) {
                   Thread sender = createSender(serverAddress, 
randomPayload(1));
                   sender.start();
                   try (SocketChannel channel = ss.accept()) {
                       channel.configureBlocking(false);
                       selector.register(Integer.toString(i), channel);
                   } finally {
                       sender.join();
                   }
               }
           }
   ```



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