Atmosphere / nettosphere

A Java WebSocket/HTTP server based on the Atmosphere and Netty Framework
http://async-io.org/
321 stars 81 forks source link

NettyWebSocket.isOpen() fails with NullPointerException. #136

Open YaroslavSaakyan opened 6 years ago

YaroslavSaakyan commented 6 years ago

I use Nettosphere 2.4.10 with Atmosphere 2.4.24. I need to close Atmosphere resource on some conditions, but webSocket.isOpen() call inside of AtmosphereResourceImpl.close() method fails with NullPointerException.

    @Override
    public void close() throws IOException {
        event.setCloseByApplication(true);
        notifyListeners();
        cancel();
        if (webSocket != null && webSocket.isOpen()) {
            webSocket.close();
        }
    }

NettyWebSocket implementation of WebSocket is used. isOpen() method calls this.channel.isOpen(), but channel field is set to null after cancel() execution. After debugging I found that the reason is a change in org.atmosphere.nettosphere.BridgeRuntime.channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) method. It calls webSocket.recycle() which sets channel field to null. Looks like it was added in version 2.4.8.

jfarcand commented 6 years ago

@YaroslavSaakyan Good job! Can you create a pull request? I will then cut a new release.

YaroslavSaakyan commented 6 years ago

@jfarcand Ok, I'll try to do it this week.