Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected and unhandled exception while closing the WebSocket connection #149

Open
CamielCop opened this issue Feb 5, 2020 · 0 comments

Comments

@CamielCop
Copy link

CamielCop commented Feb 5, 2020

Dear Nettosphere team,

We are currently seeing an Error happening in the BridgeRuntime class that could be related to how a particular client is performing the close handshake.

The client is sending the close frame to the server and immediately terminating the underlying TCP Connection. I know that the client is not following the specs for the close handshake correctly, but this is a client we do have to deal with.

In addition of the TCP connection being closed by the client, the client is also sending an unmasked close frame. The unmasked message is generating the following exception:

Feb05 17:01:33.178|ERROR||o.a.n.BridgeRuntime|784||nioEventLoopGroup-3-1|Unexpected and unhandled I/O Exception io.netty.handler.codec.http.websocketx.CorruptedWebSocketFrameException: received a frame that is not masked as expected
at io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder.protocolViolation(WebSocket08FrameDecoder.java:426)
at io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder.protocolViolation(WebSocket08FrameDecoder.java:422)
at io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder.decode(WebSocket08FrameDecoder.java:202)
at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:505)
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:444)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:283)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1422)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:931)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:700)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:635)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:552)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:514)
at io.netty.util.concurrent.SingleThreadEventExecutor$6.run(SingleThreadEventExecutor.java:1044)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:834)
Feb05 17:01:33.178|WARN||o.a.n.BridgeRuntime|764||nioEventLoopGroup-3-1|Invalid state java.lang.Error and Channel [id: 0x4c8a1c7b, L:0.0.0.0/0.0.0.0:8081] 

The exception is OK, the client is not behaving like it should. But the problem is that the WebSocketHandler::onError is never called, as the connection is being closed with an error, I would expect the onError message to be called so that I can handle the scenario in the application as well.

We are using nettosphere version 3.1.4.

This is how we start the server:

        SslContext sslNettyContext = SslContextBuilder.forServer(this.cert, this.key).protocols(this.tlsVersions).build();
        this.server = new Nettosphere.Builder().config(
                new Config.Builder()
                        .initParam(ApplicationConfig.WEBSOCKET_SUPPRESS_JSR356, "true")
                        .host(this.ip)
                        .port(this.port)
                        .sslContext(sslNettyContext)
                        .resource(PATH_V1_BETA, handleV1Beta)
                        .resource(PATH_V1, handleV1)
                        .interceptor(new WebSocketShiroInterceptor(new JwtAuthenticatedContext(new ASRConnectorSigningKeyResolver(jwtPublicKeyDir, env))))
                        .channelUpstreamHandler( new WebSocketChannelInboundHandler())
                        .build())
                .build();

        this.server.start();

Thanks,
Camiel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant