adonis0147 opened a new issue #7767: URL: https://github.com/apache/incubator-doris/issues/7767
### Search before asking - [X] I had searched in the [issues](https://github.com/apache/incubator-doris/issues?q=is%3Aissue) and found no similar issues. ### Version Computer: MacBook Pro (13-inch, M1, 2020) OS: MacOS 12.1 Doris version: master JDK version: 1.8.0_192 Intellij Idea version: 2021.3.1 (Community Edition) ### What's Wrong? I wrote a UT test case to debug some issues, but the fe failed to start frequently due to the `port already in use` exception. The port in UT is generated by the function `UtFrameUtils::findValidPort`. ```Java public static int findValidPort() { ServerSocket socket = null; try { socket = new ServerSocket(0); socket.setReuseAddress(true); return socket.getLocalPort(); } catch (Exception e) { throw new IllegalStateException("Could not find a free TCP/IP port to start HTTP Server on"); } finally { if (socket != null) { try { socket.close(); } catch (Exception e) { } } } } ``` The port was generated for `ServerSocket`. When checking the port, `NetUtils::isPortAvailable` also checks whether the port is valid for `DatagramSocket` which may failed easily in my computer when run the UT test case repeatedly. ```Java public static boolean isPortAvailable(String host, int port, String portName, String suggestion) { ServerSocket ss = null; DatagramSocket ds = null; try { ss = new ServerSocket(port); ss.setReuseAddress(true); ds = new DatagramSocket(port); ds.setReuseAddress(true); return true; } catch (IOException e) { LOG.warn("{} {} is already in use. {}", portName, port, suggestion, e); } finally { if (ds != null) { ds.close(); } if (ss != null) { try { ss.close(); } catch (IOException e) { /* should not be thrown */ } } } return false; } ``` ### What You Expected? Fe start successfully when I run the test case repeatedly. ### How to Reproduce? _No response_ ### Anything Else? _No response_ ### Are you willing to submit PR? - [X] Yes I am willing to submit a PR! ### Code of Conduct - [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct) -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
