Uploaded image for project: 'Hadoop Common'
  1. Hadoop Common
  2. HADOOP-16178

ServerSocketUtil#getPort is too smart



    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 3.3.0
    • None
    • util
    • None


      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."

      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: 

      1. Keep getPort, but rename it to getSpecificPort (or something like that). The method could keep the existing retry logic
      2. 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.




            Unassigned Unassigned
            snemeth Szilard Nemeth
            0 Vote for this issue
            1 Start watching this issue