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

异步消息存放的map pendingRPC异常情况无法回收 #5

Open
dempeZheng opened this issue Sep 19, 2016 · 1 comment
Open

异步消息存放的map pendingRPC异常情况无法回收 #5

dempeZheng opened this issue Sep 19, 2016 · 1 comment

Comments

@dempeZheng
Copy link

pendingRPC 这个ConcurrentHashMap可能会有内存溢出的风险
比如client 请求异常,或者Server返回Response异常,这个pendingRPC内的对象都无法回收

public class DefaultClientHandler extends SimpleChannelInboundHandler<RPCContext>{

    private ConcurrentHashMap<Long, RPCFuture> pendingRPC = new ConcurrentHashMap<Long, RPCFuture>();


    @Override
    protected void channelRead0(ChannelHandlerContext arg0, RPCContext rpcCtx)
            throws Exception {

        RPCFuture rpcFuture = pendingRPC.get(rpcCtx.getResponse().getSeqNum());

        if(rpcFuture != null){
            pendingRPC.remove(rpcCtx.getResponse().getSeqNum());
            rpcFuture.done(rpcCtx.getResponse());
        }
    }

    public RPCFuture doRPC(RPCContext rpcCtx){
        RPCFuture rpcFuture = new RPCFuture(rpcCtx, this);
        pendingRPC.put(rpcCtx.getRequest().getSeqNum(), rpcFuture);
        channel.writeAndFlush(rpcCtx);
        return rpcFuture;
    }

}
@dawnbreaks
Copy link
Owner

嗯,极端情况下会出现这个问题。超时和限流的机制还空缺。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants