RFR: 8037360: java/nio/channels/SocketChannel/Connect.java fails intermittently

Hamlin Li huaming.li at oracle.com
Fri Jan 15 12:05:20 UTC 2016



On 2016/1/15 19:18, Alan Bateman wrote:
> On 15/01/2016 10:18, Hamlin Li wrote:
>> Hi everyone,
>>
>> Would you please help to review the fix for bug 
>> https://bugs.openjdk.java.net/browse/JDK-8037360, 
>> java/nio/channels/SocketChannel/Connect.java fails intermittently.
>> webrev: http://cr.openjdk.java.net/~mli/8037360/webrev.00/
> Can you summarize what the issue is here? The server is binding to an 
> ephermeral port here and it shouldn't be necessary to touch SO_REUSEADDR.
Hi Alan,

One possible root cause I can figure out is a race condition which looks 
like below :
   step1, RefusingServer bind to port A, then server is closed
   step2, some other program reuse the port A, and listen on port A.
   step3, in test1(...) client connect to port A, and finish writing 
successfully(which is not expected.)
   step4, throw new Exception("Refused connection throws no exception").
in step2, we should not allow other program to listen on port A in short 
time(in when socket is in TIME_WAIT status), so use SO_REUSEADDR to 
disable socket reuse explicitly, I'm not sure what's the default 
behavior, just do some defensive fix, hope it could help.

Thank you
-Hamlin

>
> -Alan



More information about the nio-dev mailing list