Szilard Nemeth created YARN-9372:
------------------------------------
Summary: ServerSocketUtil#getPort is too smart
Key: YARN-9372
URL: https://issues.apache.org/jira/browse/YARN-9372
Project: Hadoop YARN
Issue Type: Improvement
Reporter: Szilard Nemeth
ServerSocketUtil#getPort() receives a port number and the number of retries to
look for other free ports if the specified port is already used.
This could be useful for certain cases where the tests do want a specified port
to be opened, I think this is very rare, though.
Most of the time, the testcase just wants a free port and don't care about the
specific port opened.
According to this:
[https://stackoverflow.com/questions/2675362/how-to-find-an-available-port]
and the constructor of ServerSocket
([https://docs.oracle.com/javase/7/docs/api/java/net/ServerSocket.html#ServerSocket%28int%29)]
:
"A port number of {{0}} means that the port number is automatically allocated,
typically from an ephemeral port range. This port number can then be retrieved
by calling
[{{getLocalPort}}|https://docs.oracle.com/javase/7/docs/api/java/net/ServerSocket.html#getLocalPort()]."
Checked most of the calls, the tests are calling this method with port numbers
above 49000 so they obviously don't really care about the port being allocated.
So I could image two methods here:
# Keep getPort, but rename it to getSpecificPort (or something like that). The
method could keep the existing retry logic
# Create a new method (could be named "getPort") that simply invokes
ServerSocket with a value of 0, indicating that it wants any open port in the
ephemeral range. Most of the testcases (if not all) should use this method. The
retry logic shouldn't be part of this new method as it is very unlikely that no
port could be allocated at all.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]