@Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
      // Close the channel would force netty to flush the remaining buffer back to client. If the flush operation
      // fails due to exceptions, when this method would be invoked again. And we would fall into an infinite loop
      // of stack trace. So use a boolean value to make sure we only do close once.
      if (closed.compareAndSet(false, true)) {
        http2ServerMetrics.http2ParentExceptionCount.inc();
        logger.warn("Parent channel {} exception: ", ctx.channel(), cause);
        ctx.channel().close();
      }
    }
Netty calls this function when channel becomes inactive. The channel becomes inactive AFTER it is closed (either by
the local or the remote end). One case is when server shutdown.
ambry-rest/src/main/java/com/github/ambry/rest/StorageServerNettyChannelInitializer.java