Jackie-Jiang commented on a change in pull request #6872: URL: https://github.com/apache/incubator-pinot/pull/6872#discussion_r625312525
########## File path: pinot-spi/src/main/java/org/apache/pinot/spi/utils/NetUtils.java ########## @@ -57,4 +59,29 @@ public static String getHostnameOrAddress() { } } } + + /** + * Find an open port. + * @return an open port + * @throws IOException + */ + public static int findOpenPort() + throws IOException { + try (ServerSocket socket = new ServerSocket(0)) { + return socket.getLocalPort(); + } + } + + /** + * Find an open port,otherwise use given default port. + * @param defaultPort + * @return an open port otherwise default port + */ + public static int findOpenPort(int defaultPort) { Review comment: Also, it might be better to try `defaultPort + i` until we get an open port so that the port number is more deterministic -- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org