xcx1r3 opened a new pull request, #2263:
URL: https://github.com/apache/zookeeper/pull/2263

   # Description
   Any exception occurring before both `close()` calls complete successfully 
can lead to one or both `ServerSocket` instances (and the system ports they 
hold) not being released.
   The best way to fix this is to use the `try-with-resources` statement, which 
guarantees that `Closeable` resources are closed, even if exceptions occur.
   ```
   int quorumPort;
           int electionPort;
   
           // Use try-with-resources to find available ports and ensure sockets 
are closed
           try (ServerSocket randomSocket1 = new ServerSocket(0);
                ServerSocket randomSocket2 = new ServerSocket(0)) {
   
               quorumPort = randomSocket1.getLocalPort();
               electionPort = randomSocket2.getLocalPort();
   
           }


-- 
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: notifications-unsubscr...@zookeeper.apache.org

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

Reply via email to