You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "frankvicky (via GitHub)" <gi...@apache.org> on 2024/07/30 03:19:22 UTC

[PR] KAFKA-17201: SelectorTest.testInboundConnectionsCountInConnectionCreationMetric leaks sockets and threads [kafka]

frankvicky opened a new pull request, #16723:
URL: https://github.com/apache/kafka/pull/16723

   Currently, the sockets and threads created in `testInboundConnectionsCountInConnectionCreationMetric` have not been closed, and this issue needs to be fixed.
   
   ### Committer Checklist (excluded from commit message)
   - [ ] Verify design and implementation 
   - [ ] Verify test coverage and CI build status
   - [ ] Verify documentation (including upgrade notes)
   


-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-17201: SelectorTest.testInboundConnectionsCountInConnectionCreationMetric leaks sockets and threads [kafka]

Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-17201: SelectorTest.testInboundConnectionsCountInConnectionCreationMetric leaks sockets and threads [kafka]

Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 merged PR #16723:
URL: https://github.com/apache/kafka/pull/16723


-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-17201: SelectorTest.testInboundConnectionsCountInConnectionCreationMetric leaks sockets and threads [kafka]

Posted by "frankvicky (via GitHub)" <gi...@apache.org>.
frankvicky commented on PR #16723:
URL: https://github.com/apache/kafka/pull/16723#issuecomment-2268110038

   Hi @chia7712 
   I have address the comment, PTAL 😃 


-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-17201: SelectorTest.testInboundConnectionsCountInConnectionCreationMetric leaks sockets and threads [kafka]

Posted by "frankvicky (via GitHub)" <gi...@apache.org>.
frankvicky commented on code in PR #16723:
URL: https://github.com/apache/kafka/pull/16723#discussion_r1703491837


##########
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:
   Thanks @chia7712 
   I think this suggestion is very insightful, I will follow it 😃 



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org