Tencent / TubeMQ

TubeMQ has been donated to the Apache Software Foundation and renamed to InLong, please visit the new Apache repository: https://github.com/apache/incubator-inlong
https://inlong.apache.org/
2.02k stars 388 forks source link

RPC problem #101

Closed aloyszhang closed 5 years ago

aloyszhang commented 5 years ago

I found some confusing code in NettyClient#call.

if (channel1 == null) {
            logger.error(new StringBuilder(256)
                    .append(this.addressInfo.getHostPortStr())
                    .append("'s channel is null").toString());
        } else {
            getChannel().write(pack);
        }
        if (callback == null) {
            try {
                return future.get(timeout, timeUnit);
            } catch (TimeoutException e) {
                requests.remove(request.getSerialNo());
                throw e;
            }
        } else {
            timeouts.put(request.getSerialNo(),
                    timer.newTimeout(new TimeoutTask(request.getSerialNo()), timeout, timeUnit));
        }

when channel is null, it'll continue run the following code. It seems meaningless since client can't send request when channel is null. I think maybe throw a RuntimeExcetion indicate channel is null is a better way.

Another problem here, currently, when send message asynchronously, it will build a Timeout after write data to channel. Since build a timeout may cause RuntimeException, it will trigger callback twice in this situaitons.

aloyszhang commented 5 years ago

@gosonzhang

gosonzhang commented 5 years ago

Thanks, @aloyszhang, can you contribute a PR to this question?