<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <p>Hi Max,<br>
    </p>
    <div class="moz-cite-prefix">On 2016/7/9 18:04, Wang Weijun wrote:<br>
    </div>
    <blockquote
      cite="mid:6C71C399-9776-470C-AFA5-81C387BA7B6A@oracle.com"
      type="cite">
      <pre wrap="">I am not sure. If in the first round a free port is chosen for UDP but it's not available for TCP, how can we avoid the same port being chosen again in the 2nd round? The DatagramSocket object is closed in the catch block and the port number is reclaimed by the OS. Will the OS reuse it immediately in the 2nd round?</pre>
    </blockquote>
    I tested the case with the below codes on Windows and Linux,<br>
    <br>
    for (int i = 0; i < 100; i++) {<br>
        try (ServerSocket ss = new ServerSocket(0)) {<br>
            int port = ss.getLocalPort();<br>
            System.out.println(port);<br>
            try (DatagramSocket us = new DatagramSocket(port,<br>
                    InetAddress.getByName("127.0.0.1"))) {<br>
            }<br>
        }<br>
    <br>
        Thread.sleep(500);<br>
    }<br>
    <br>
    The outputs like the followings:<br>
    Windows 7:<br>
        57632<br>
        57633<br>
        57634<br>
        57635<br>
        57636<br>
        57637<br>
        57638<br>
        57639<br>
        57640<br>
        57641<br>
        57642<br>
        57643<br>
        57644<br>
        57645<br>
        57646<br>
        57647<br>
        57648<br>
        57649<br>
        57650<br>
        57651<br>
       ...<br>
    <br>
    Ubuntu 15.10:<br>
        45916<br>
        44807<br>
        33578<br>
        40244<br>
        46033<br>
        38966<br>
        34431<br>
        46026<br>
        40069<br>
        39013<br>
        39496<br>
        37745<br>
        36749<br>
        43594<br>
        45667<br>
        46410<br>
        36762<br>
        38565<br>
        35074<br>
        34843<br>
        ...<br>
    <br>
    With the results, the previous port is not reused by the subsequent
    round immediately.<br>
    <br>
    Best regards,<br>
    John Jiang<br>
    <blockquote
      cite="mid:6C71C399-9776-470C-AFA5-81C387BA7B6A@oracle.com"
      type="cite">
      <pre wrap="">
--Max

</pre>
      <blockquote type="cite">
        <pre wrap="">On Jul 9, 2016, at 3:18 PM, John Jiang <a class="moz-txt-link-rfc2396E" href="mailto:sha.jiang@oracle.com"><sha.jiang@oracle.com></a> wrote:

Hi Max,

On 2016/7/8 16:19, Wang Weijun wrote:
</pre>
        <blockquote type="cite">
          <pre wrap="">The reason a loop is needed here is that both the TCT and UDP servers must listen on the same port number. With your fix, the TCP server finds a free port, but I doubt if it's free for the UDP server.
</pre>
        </blockquote>
        <pre wrap="">Yes, it's possible that the port still be occupied by another DatagramSocket.
Please review the updated webrev: <a class="moz-txt-link-freetext" href="http://cr.openjdk.java.net/%7Ejjiang/8160029/webrev.01">http://cr.openjdk.java.net/~jjiang/8160029/webrev.01</a>

Best regards,
John Jiang

</pre>
        <blockquote type="cite">
          <pre wrap="">--Max


</pre>
          <blockquote type="cite">
            <pre wrap="">On Jul 8, 2016, at 2:35 PM, John Jiang <a class="moz-txt-link-rfc2396E" href="mailto:sha.jiang@oracle.com"><sha.jiang@oracle.com></a> wrote:

Hi,
Would you like to review this patch for removing unnecessary usages on jdk.testlibrary.Utils.getFreePort() from security-libs tests?
In OpenJDK, I find only sun/security/krb5/auto/KDC.java should be modified for this issue.
If I miss something, please let me know.

Issue: <a class="moz-txt-link-freetext" href="https://bugs.openjdk.java.net/browse/JDK-8160029">https://bugs.openjdk.java.net/browse/JDK-8160029</a>
Webrev: <a class="moz-txt-link-freetext" href="http://cr.openjdk.java.net/%7Ejjiang/8160029/webrev.00">http://cr.openjdk.java.net/~jjiang/8160029/webrev.00</a>

Thanks!

John Jiang


</pre>
          </blockquote>
        </blockquote>
      </blockquote>
      <pre wrap="">
</pre>
    </blockquote>
    <br>
  </body>
</html>