code: def _reset_on_error(self, server_address, session):
          
          try:
              try:
                  yield
              except PyMongoError as exc:
                  if session and exc.has_error_label(
                          "TransientTransactionError"):
                      session._unpin_mongos()
                  raise
          except NetworkTimeout:
              # The socket has been closed. Don't reset the server.
              # Server Discovery And Monitoring Spec: "When an application
              # operation fails because of any network error besides a socket
              # timeout...."
              raise
          except NotMasterError:
              # "When the client sees a "not master" error it MUST replace the
              # server's description with type Unknown. It MUST request an
              # immediate check of the server."
              self._reset_server_and_request_check(server_address)
              raise
          except ConnectionFailure:
              # "Client MUST replace the server's description with type Unknown
              # ... MUST NOT request an immediate check of the server."
              self.__reset_server(server_address)
              raise
          except OperationFailure as exc:
              if exc.code in helpers._RETRYABLE_ERROR_CODES:
                  # Do not request an immediate check since the server is likely
                  # shutting down.
                  self.__reset_server(server_address)
              raise
docs: On "not master" or "node is recovering" errors reset the server
          according to the SDAM spec.
  
          Unpin the session on transient transaction errors.