diff --git a/rskj-core/src/main/java/co/rsk/rpc/netty/RskWebSocketJsonRpcHandler.java b/rskj-core/src/main/java/co/rsk/rpc/netty/RskWebSocketJsonRpcHandler.java index 4e04d53db4c..9ca60558307 100644 --- a/rskj-core/src/main/java/co/rsk/rpc/netty/RskWebSocketJsonRpcHandler.java +++ b/rskj-core/src/main/java/co/rsk/rpc/netty/RskWebSocketJsonRpcHandler.java @@ -66,12 +66,14 @@ public RskWebSocketJsonRpcHandler(EthSubscriptionNotificationEmitter emitter, Js } @Override - protected void channelRead0(ChannelHandlerContext ctx, ByteBufHolder msg) { + protected void channelRead0(ChannelHandlerContext ctx, ByteBufHolder msg) throws IOException { ByteBuf content = null; + ByteBufInputStream source = null; try { content = msg.content().copy(); - RskJsonRpcRequest request = serializer.deserializeRequest(new ByteBufInputStream(content)); + source = new ByteBufInputStream(content); + RskJsonRpcRequest request = serializer.deserializeRequest(source); // TODO(mc) we should support the ModuleDescription method filters JsonRpcResultOrError resultOrError = request.accept(this, ctx); @@ -83,6 +85,10 @@ protected void channelRead0(ChannelHandlerContext ctx, ByteBufHolder msg) { // We need to release this resource, netty only takes care about 'ByteBufHolder msg' content.release(content.refCnt()); + } finally { + if(source != null) { + source.close(); + } } // delegate to the next handler if the message can't be matched to a known JSON-RPC request