Skip to content

Commit

Permalink
netty: fix leak + disconnected websocket clients
Browse files Browse the repository at this point in the history
- WebSocket onClose not called for Netty fix #3452
- Memory leak in jooby-netty fix #3453
  • Loading branch information
jknack committed Jun 20, 2024
1 parent 9283105 commit e0e30bf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,17 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) {
}
}
} else if (isLastHttpContent(msg)) {
// when decoder == null, chunk is always a LastHttpContent.EMPTY, ignore it
if (context.decoder != null) {
offer(context, (HttpContent) msg);
Router.Match route = router.match(context);
resetDecoderState(context, !route.matches());
route.execute(context);
var chunk = (HttpContent) msg;
try {
// when decoder == null, chunk is always a LastHttpContent.EMPTY, ignore it
if (context.decoder != null) {
offer(context, chunk);
Router.Match route = router.match(context);
resetDecoderState(context, !route.matches());
route.execute(context);
}
} finally {
release(chunk);
}
} else if (isHttpContent(msg)) {
var chunk = (HttpContent) msg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ public NettyWebSocket(NettyContext ctx) {
this.netty = ctx;
this.key = ctx.getRoute().getPattern();
this.dispatch = !ctx.isInIoThread();
this.netty.ctx.channel().attr(WS).set(this);
var channel = this.netty.ctx.channel();
channel.attr(WS).set(this);
channel.closeFuture().addListener(future -> handleClose(WebSocketCloseStatus.GOING_AWAY));
}

@NonNull @Override
Expand Down

0 comments on commit e0e30bf

Please sign in to comment.