12

specifically i am interested in the case where the other end of the channel dies unexpectedly (eg the process gets killed). it seems that netty does not reliably fire a channel closed/disconnect event, sometimes it does and sometimes it does not. it also does not necessarily throw a SocketException for connection reset.

for what it's worth, i have also tried writing to the channel but this also continues to work without throwing exceptions or firing any other events.

i am testing this on windows, with netty 3.3.0.Final, if that makes any difference.

Christopher Ng
  • 153
  • 1
  • 5

2 Answers2

1

If a channel disconnects without sending close there is no way to detect it. Usually the best way to detect a disconnect if needed is to periodically send heartbeat events over the channel ever x seconds. Using IdleStateHandler, if you don't receive the heartbeat after the heartbeat + a delta you force disconnect the channel.

Josh Wilson
  • 3,585
  • 7
  • 32
  • 53
0

Try using the method channelUnregistered from the ChannelInboundHandlerAdapter class.

public void channelUnregistered(ChannelHandlerContext ctx) throws Exception {
  ctx.fireChannelUnregistered();
  //Your logic goes here...
}