code: static void closeOnFlush(Channel ch) {
          if (ch.isActive()) {
              ch.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE);
          }
      }
docs: Closes the specified channel after all queued write requests are flushed.