@Override
  public void channelInactive(final ChannelHandlerContext ctx) throws Exception {
    volatileContext = null; // Make sure future `sendRequest` calls fail.

    Exception connectionClosed = new NotConnectedException("Channel became inactive while awaiting response.");
    for (OutstandingRequest request : outstandingRequests) {
      try {
        request.promise.setFailure(connectionClosed);
      } catch (Throwable t) {
        LOGGER.error("Failed to set promise failure", t);
      }
    }
    outstandingRequests.clear();

    super.channelInactive(ctx);
  }
@ Override public void channelInactive ( final ChannelHandlerContext ctx ) throws Exception { volatileContext = null ; Exception connectionClosed = new NotConnectedException ( "Channel became inactive while awaiting response." ) ; for ( OutstandingRequest request : outstandingRequests ) { try { request . promise . setFailure ( connectionClosed ) ; } catch ( Throwable t ) { LOGGER . error ( "Failed to set promise failure" , t ) ; } } outstandingRequests . clear ( ) ; super . channelInactive ( ctx ) ; }
Fails all the promises in the {@link #outstandingRequests} queue when the
channel becomes inactive.
<p>
Netty always invokes this method in the event loop thread. To ensure
this method never runs concurrently with {@link #unsafeSendRequest},
we only call that method in the event loop thread as well.