Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak in HTTP protocols #162

Closed
raptium opened this issue Apr 7, 2020 · 2 comments
Closed

Memory leak in HTTP protocols #162

raptium opened this issue Apr 7, 2020 · 2 comments
Assignees
Labels
bug Something isn't working In Progress Project is in progress

Comments

@raptium
Copy link
Collaborator

raptium commented Apr 7, 2020

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 raptium self-assigned this Apr 7, 2020
@raptium raptium added bug Something isn't working In Progress Project is in progress labels Apr 7, 2020
@raptium raptium changed the title Memory Leak in HTTP protocols Memory leak in HTTP protocols Apr 7, 2020
@raptium raptium mentioned this issue Apr 30, 2020
Closed
@raptium
Copy link
Collaborator Author

raptium commented May 7, 2020

We now have a quick and dirty fix in 1926856.

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

@haijunzou1985
Copy link

haijunzou1985 commented Sep 29, 2021

那这次请求,是没有返回的,客户端直接报异常?解析不出请求,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);

        }
    }
}

@tullyliu tullyliu closed this as completed Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working In Progress Project is in progress
Projects
None yet
Development

No branches or pull requests

3 participants