code: def connectionLost(self, reason=None):
          
          try:
              self.connected = False
              self.stop_block_loop()
              self.stop_peerinfo_loop()
              self.stop_header_loop()
  
              self.ReleaseBlockRequests()
              self.leader.RemoveConnectedPeer(self)
  
              time_expired = self.time_expired(HEARTBEAT_BLOCKS)
              # some NEO-cli versions have a 30s timeout to receive block/consensus or tx messages. By default neo-python doesn't respond to these requests
              if time_expired > 20:
                  self.address.last_connection = Address.Now()
                  self.leader.AddDeadAddress(self.address, reason=f"{self.prefix} Premature disconnect")
  
              if reason and reason.check(twisted_error.ConnectionDone):
                  # this might happen if they close our connection because they've reached max peers or something similar
                  logger.debug(f"{self.prefix} disconnected normally with reason:{reason.value}")
                  self._check_for_consecutive_disconnects("connection done")
  
              elif reason and reason.check(twisted_error.ConnectionLost):
                  # Can be due to a timeout. Only if this happened again within 5 minutes do we label the node as bad
                  # because then it clearly doesn't want to talk to us or we have a bad connection to them.
                  # Otherwise allow for the node to be queued again by NodeLeader.
                  logger.debug(f"{self.prefix} disconnected with connectionlost reason: {reason.value}")
                  self._check_for_consecutive_disconnects("connection lost")
  
              else:
                  logger.debug(f"{self.prefix} disconnected with reason: {reason.value}")
          except Exception as e:
              logger.error("Error with connection lost: %s " % e)
  
          def try_me(err):
              err.check(error.ConnectionAborted)
  
          if self.disconnect_deferred:
              d, self.disconnect_deferred = self.disconnect_deferred, None  # type: defer.Deferred
              d.addErrback(try_me)
              if len(d.callbacks) > 0:
                  d.callback(reason)
              else:
                  print("connLost, disconnect_deferred cancelling!")
                  d.cancel()
docs: Callback handler from twisted when a connection was lost.