This works fine, but I have started stress testing recently, and am now opening lots of connections at once in say 10 or more threads. Now I sometimes get BindExceptions:
socketChannel = SocketChannel.open(); socketChannel.configureBlocking(true); socketChannel.connect( new InetSocketAddress(connectRequest.getAddress(), connectRequest.getPort())); // i.e. The address of the server I am attempting to connect to.
What is causing this? Is it a bug with the SocketChannelImpl? Could it be that I am not closing my connections properly, and consequently running out of local ports or file handles (I don't think I am failing to close connections)?
testSession(com.rapidaddition.genzero.stress.SessionStressTest) java.lang.RuntimeException: java.net.BindException: Cannot assign requested address ... Caused by: java.net.BindException: Cannot assign requested address at sun.nio.ch.Net.connect(Native Method) at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:507)
Which is the socket waiting for a while whilst closing down. My stress test must be churning the connections too fast, and running out of local ports or file handles or something, as a closed TCP connection remains active for some time after it is closed.
tcp6 0 0 localhost:55955 localhost:7777 TIME_WAIT