Alan Bateman wrote: > Sent: Thursday, September 29, 2011 16:30 > To: Jeroen Frijters > Cc: net-dev@openjdk.java.net > Subject: Re: non-blocking SocketChannel connect broken on Windows 8 > > Jeroen Frijters wrote: > > Hi, > > > > While testing on Windows 8 I found a bug in > SocketChannelImpl.connect() when configured non-blocking. > > > > Here's repro: > > > > import java.net.*; > > import java.nio.channels.*; > > > > public class test > > { > > public static void main(String[] args) throws Exception > > { > > SocketChannel sc = SocketChannel.open(); > > sc.configureBlocking(false); > > sc.connect(new InetSocketAddress("google.com", 12345)); > > } > > } > > > > When run on the Windows 8 Developer Preview this throws the following > exception: > > > > Exception in thread "main" java.net.SocketException: Invalid argument: > getsockname > > at sun.nio.ch.Net.localInetAddress(Native Method) > > at sun.nio.ch.Net.localAddress(Net.java:389) > > at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:639) > > at test.main(test.java:10) > > > > When you look at the code the problem is obvious. The connect method > tries to get the localAddress while the connection is still pending, it > should only do this after the connection attempt has finished. > > > This must be behavior change in Windows 8 as I don't think we've seen > this before (as we have several tests that do non-blocking connects). > The usual thing when you attempt to connect is that the operating system > should first bind to a local address (if not bound already) before it > attempts to establish the connection. I've no doubt that this will break > other things too.
It's definitely a behavior change in Windows 8 and I agree that it probably has some compatibility impact, but fundamentally I think that the OpenJDK code is wrong, unless there is documentation somewhere that claims that the socket will be bound when the async connect is initiated. Regards, Jeroen