jooby-project / jooby

The modular web framework for Java and Kotlin
https://jooby.io
Apache License 2.0
1.68k stars 199 forks source link

WebSocket onClose not called for Netty #3452

Closed U1F984 closed 3 weeks ago

U1F984 commented 4 weeks ago

After switching from jooby-undertow to jooby-netty, issue #3111 can be reproduced again with the lastest version. Using undertow with the latest version works correctly ("Connected" followed by "Disconnected").

If the socket is actively used by writing to it, there is an error:

java.lang.IllegalStateException: Attempt to send a message on closed web socket
    at io.jooby.internal.netty.NettyWebSocket.sendMessage(NettyWebSocket.java:178)
    at io.jooby.internal.netty.NettyWebSocket.send(NettyWebSocket.java:111)
    at io.jooby.WebSocket.send(WebSocket.java:205)
    at App$1$1$1.invoke(ServerMain.kt:16)
    at App$1$1$1.invoke(ServerMain.kt:13)
    at kotlin.concurrent.ThreadsKt$thread$thread$1.run(Thread.kt:30)

and the socket is marked as closed (isOpen returns true since the netty channel is dead), but the handleClose and so onClose callback is not invoked.

If I insert:

this.netty.ctx.channel().closeFuture().addListener(future -> handleClose(WebSocketCloseStatus.GOING_AWAY)); // or some other close status

into the constructor, the onClose is invoked successfully.

jknack commented 3 weeks ago

@U1F984 would you like to send a PR?