8201474: (so) Socket adaptor connect(InetAddress, timeout) succeeds when connection fails

Alan Bateman Alan.Bateman at oracle.com
Thu Apr 12 12:48:08 UTC 2018


This is a regression in JDK 11 where a java.net.Socket is obtained from 
a SocketChannel and its 2-arg connect method is used to attempt a 
connection and the connect fails. The implementation incorrectly sets 
the state to connected for this case. The 1-arg (no timeout) connect 
doesn't have this issue.

For the timeout case, the socket adaptor uses pollConnected. This is 
blocking so the poll is wrapped by beginFinishConnect/end to support 
interrupt and async/close. The bug is that endFinishConnect is called 
with completed=true when any events are polled, including error events, 
so the connection state is set to indicate that the connection is 
established. The changes are simple:

http://cr.openjdk.java.net/~alanb/8201474/webrev/index.html

(Thank you to whoever reported JDK-8201474).

-Alan


More information about the nio-dev mailing list