接続障害時のクライアント サーバーの処理をテストしています。
クライアント側では、クライアントからサーバーにメッセージを送信するときに LAN ケーブルを抜いたときに ChannelFuture (以下) が呼び出されません。私が予想していたのは、ChannelFuture によって例外がキャッチされるので、それを operationComplete で処理できるということでした。
代わりに、クライアントのパイプラインの最後のアップストリーム ハンドラーでキャッチされるだけです。私は何か間違ったことをしていますか?それとも、これは Netty 3.2.4 の問題でしょうか?
LAN ケーブルを抜いたときにハンドラーで発生する例外:
java.io.IOException: An existing connection was forcibly closed by the remote host
at sun.nio.ch.SocketDispatcher.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:25)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:198)
at sun.nio.ch.IOUtil.read(IOUtil.java:166)
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:243)
at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:321)
at org.jboss.netty.channel.socket.nio.NioWorker.processSelectedKeys(NioWorker.java:280)
at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:200)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
私のチャンネル未来:
ChannelFuture future = Channels.write(channel, message);
future.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (!future.isSuccess()) {
LOG.error("Client failed to send message", future.getCause());
future.getChannel().close();
}
}
});