starlight icon indicating copy to clipboard operation
starlight copied to clipboard

Memory leak in HTTP protocols

Open raptium opened this issue 4 years ago • 2 comments

When BrpcHttpObjectDecoder.decode() is called, a BrpcHttpObjectAggregator instance is created and used to aggregate tcp packets into complete HTTP messages. decode() returns null if there is not enough data in buffer, however BrpcHttpObjectAggregator retains ByteBuf even if there is not enough data to form a complete HTTP message.

This affects all HTTP protocol implementations using BrpcHttpObjectDecoder on both client and server sides.

raptium avatar Apr 07 '20 08:04 raptium

We now have a quick and dirty fix in 1926856d1cbbf35ea964df9387b3e65b80b9e8f8.

Maybe we should refactor the HTTP protocol implementation to get a better resolution.

raptium avatar May 07 '20 01:05 raptium

那这次请求,是没有返回的,客户端直接报异常?解析不出请求,break了(NotEnoughDataException)。这个框架,是不是没有拆包,粘包的解决方案? public void channelRead0(ChannelHandlerContext ctx, Object in) throws Exception { ChannelInfo channelInfo = ChannelInfo.getServerChannelInfo(ctx.channel()); ByteBuf msg = (ByteBuf) in; int len = msg.readableBytes(); if (len > 0) { channelInfo.getRecvBuf().addBuffer(msg.retain()); DecodeWorkTask[] tasks = new DecodeWorkTask[64]; int i = 0; while (channelInfo.getRecvBuf().readableBytes() > 0) { try { Object packet = decodeHeader(ctx, channelInfo, channelInfo.getRecvBuf()); DecodeWorkTask task = new DecodeWorkTask(rpcServer, packet, channelInfo.getProtocol(), ctx); tasks[i++] = task; if (i == 64) { rpcServer.getThreadPool().submit(tasks, 0, i); i = 0; } } catch (NotEnoughDataException ex1) { break; } catch (TooBigDataException ex2) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, ex2); } catch (BadSchemaException ex3) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, ex3); } } if (i > 0) { rpcServer.getThreadPool().submit(tasks, 0, i);

        }
    }
}

haijunzou1985 avatar Sep 29 '21 11:09 haijunzou1985