I'm having a apparently random problem when calling setTcpNoDelay() on a Socket object from a SocketChannel. One of my servers was getting flooded with connections from one IP address, and these exceptions kept getting thrown:
[LoginAuthentication-986]Accepting connection from 72.69.198.152
java.net.SocketException: Socket operation on nonsocket: sun.nio.ch.Net.setIntOption
at sun.nio.ch.Net.setIntOption0(Native Method)
at sun.nio.ch.Net.setIntOption(Net.java:154)
at sun.nio.ch.SocketChannelImpl$1.setInt(SocketChannelImpl.java:406)
at sun.nio.ch.SocketOptsImpl.setBoolean(SocketOptsImpl.java:38)
at sun.nio.ch.SocketOptsImpl$IP$TCP.noDelay(SocketOptsImpl.java:284)
at sun.nio.ch.OptionAdaptor.setTcpNoDelay(OptionAdaptor.java:48)
at sun.nio.ch.SocketAdaptor.setTcpNoDelay(SocketAdaptor.java:268)
at LoginAuthentication.handleLogin(LoginAuthentication.java:232)
at net.allgofree.SharedBlitzIO.Authentication.Authenticator.updateAction(Authenticator.java:110)
at net.allgofree.Updater.Updater.doUpdating(Updater.java:114)
at server.main(server.java:366)
[LoginAuthentication-986]Login failed:java.net.SocketException: Socket operation on nonsocket: sun.nio.ch.Net.setIntOption
Here is the code that is generating the exception:
debug("Connection accepted from " + connectionStream.getInetAddress().getHostAddress());
connectionStream.getSocket().setTcpNoDelay(true);
waitForBytes(1);
In this case getSocket() is getting the Socket object from java.nio.channels.SocketChannel.socket().
Does anyone know what is causing this or how to fix it?