I created a neat little feedback loop the other day with @Override public void exceptionCaught(IoSession session, Throwable cause) throws Exception { session.write(cause); }
I'm trying to take uncaught exceptions and push them over the wire... When a client connection disconnects abruptly session.write() will throw an IOException stating that fact. In a few seconds I'm completely out of heap space. That's fun. So I have two questions... First, I suspect this is sensible, but should I be more specific than just IOException: @Override public void exceptionCaught(IoSession session, Throwable cause) throws Exception { if (!(cause instanceof IOException)) { try { session.write(cause); } catch (Exception e) { e.printStackTrace(); } } } Second, is there a specific graceful way to disconnect a client? I'm trying to disconnect gracefully if the server response is taking longer than a specified time with now = new Date(); long remaining = (new Date(start.getTime() + timeout)).getTime() - now.getTime(); CloseFuture closeFuture = future.getSession().close(false); try { closeFuture.await(remaining); } catch (InterruptedException e) { //do nothing } //tired of waiting, or we're closed: connector.dispose();