code: def close(self):
          
          log.debug('%r: close() proto=%r connector=%r', self, self.proto, self.connector)
          assert self._dDown is None
          self._dDown = Deferred()
  
          if self.proto is not None:
              self.proto.transport.loseConnection()
          elif self.connector is not None:
              def connectingFailed(reason):
                  """
                  Handle the failure resulting from cancellation.
  
                  :reason: a `Failure`, most likely a cancellation error (but
                      that's not guaranteed).
                  :returns: `None` to handle the failure
                  """
                  log.debug('%r: connection attempt has been cancelled: %r', self, reason)
                  self._dDown.callback(None)
  
              self.connector.addErrback(connectingFailed)
              self.connector.cancel()
          else:
              # Fake a cleanly closing connection
              self._dDown.callback(None)
  
          try:
              raise CancelledError(message="Broker client for node_id={} {}:{} was closed".format(
                  self.node_id, self.host, self.port))
          except Exception:
              reason = Failure()
          # Cancel any requests
          for correlation_id in list(self.requests.keys()):  # must copy, may del
              self.cancelRequest(correlation_id, reason)
          return self._dDown
docs: Permanently dispose of the broker client.
  
          This terminates any outstanding connection and cancels any pending
          requests.