code: @GuardedBy("lock")
    private void stopIfNecessary() {
      if (!(goAwayStatus != null && streams.isEmpty() && pendingStreams.isEmpty())) {
        return;
      }
      if (stopped) {
        return;
      }
      stopped = true;
  
      if (keepAliveManager != null) {
        keepAliveManager.onTransportTermination();
        // KeepAliveManager should stop using the scheduler after onTransportTermination gets called.
        scheduler = SharedResourceHolder.release(TIMER_SERVICE, scheduler);
      }
  
      if (ping != null) {
        ping.failed(getPingFailure());
        ping = null;
      }
  
      if (!goAwaySent) {
        // Send GOAWAY with lastGoodStreamId of 0, since we don't expect any server-initiated
        // streams. The GOAWAY is part of graceful shutdown.
        goAwaySent = true;
        frameWriter.goAway(0, ErrorCode.NO_ERROR, new byte[0]);
      }
  
      // We will close the underlying socket in the writing thread to break out the reader
      // thread, which will close the frameReader and notify the listener.
      frameWriter.close();
    }
docs: When the transport is in goAway state, we should stop it once all active streams finish.