Skip to content

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

@dempeZheng

Description

@dempeZheng

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;
    }

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions