Netty Channel.close()偶尔挂起。在我们的特殊使用案例中,我们拥有一批渠道,我们的测试检查是否容忍网络故障。所以,在我们的测试中,我们试图关闭一个频道。Netty Channel.close()间歇性挂起
在下面的代码片段中,我们在调用Channel.close()之前,在Channel.close()之后,以及在ChannelFuture.await()之后立即打印调试语句。为了确保线程不被中断,我们检查InterruptedException。
Channel c = partitionChannelMap.get(partition);
if (c != null) {
for (int retries = 0; retries < numRetries; retries++) {
try {
logger.debug("Attempt {}: Closing channel to partition {}", retries + 1, partition);
logger.debug("Channel Properties - isBound() isConnected() isOpen() " + c.isBound() + " "
+ c.isConnected() + " " + c.isOpen());
ChannelFuture closeFuture = c.close();
logger.debug("About to wait");
closeFuture.await(nettyTimeout);
if (closeFuture.isSuccess()) {
logger.debug("Attempt {}: CLOSED channel to partition {}", retries + 1, partition);
partitionChannelMap.remove(partition);
break;
} else {
logger.error("Attempt {}: FAILED to close partition {}", retries + 1, partition);
continue;
}
} catch (InterruptedException e) {
logger.error("Attempt {}: FAILED to close partition {}", retries + 1, partition);
e.printStackTrace();
continue;
}
}
}
}
在一些运行(错误的)的,Channel.close前的调试语句()被执行,而不要立即之后。由于Channel.close()是异步的,我们期待它立即返回。在这些情况下,调用Channel.close()后执行挂起。
我在这里假设或做错了什么?
样品输出错误执行 -
15:12:32.497 [Thread-7] DEBUG org.apache.s4.comm.tcp.TCPEmitter - Attempt 1: Closing channel to partition 0
15:12:32.497 [Thread-7] DEBUG org.apache.s4.comm.tcp.TCPEmitter - Channel Properties - isBound() isConnected() isOpen() true true true
我真的很感激有这方面的帮助。
谢谢