starlight
starlight copied to clipboard
Memory leak in HTTP protocols
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.
We now have a quick and dirty fix in 1926856d1cbbf35ea964df9387b3e65b80b9e8f8.
Maybe we should refactor the HTTP protocol implementation to get a better resolution.
那这次请求,是没有返回的,客户端直接报异常?解析不出请求,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);
}
}
}