NPE SocketChannelIOHelper.read() channel is null [WSS] #349
Closed
Description
I randomly get this exception (few times a day). it totally blocks any further processing of messages and handshakes, and I have to restart the app.
java.lang.NullPointerException
at org.java_websocket.SocketChannelIOHelper.read(SocketChannelIOHelper.java:14)
at org.java_websocket.server.WebSocketServer.run(WebSocketServer.java:324)
at java.lang.Thread.run(Thread.java:745)
I'm only using WSS with a signed cert, so I don't really know if it would arise without SSL.
I'll report later on that.
The function is called in WebSocketServer.run() during the socket selection loop :
if( key.isReadable() ) {
conn = (WebSocketImpl) key.attachment();
ByteBuffer buf = takeBuffer();
try {
if( SocketChannelIOHelper.read( buf, conn, conn.channel ) ) {
Trying to patch with the following is actually not helping, the server still not responding to any message or handshake any more. I'm guessing the server socket is the one affected, since it
can also happen when no client is connected.
public static boolean read( final ByteBuffer buf, WebSocketImpl ws, ByteChannel channel ) throws IOException {
if(channel==null){
System.out.println("channel is null");
ws.eot();
return false;
}
...
}
using a variation without ws.eot() is printing "channel is null" infinitely.
I'll report more asap, but if anyone has a clue?