def _set_defunct(self, message, error=None): direct_driver = isinstance(self.pool, BoltPool) if error: log.error(str(error)) log.error(message) # We were attempting to receive data but the connection # has unexpectedly terminated. So, we need to close the # connection from the client side, and remove the address # from the connection pool. self._defunct = True self.close() if self.pool: self.pool.deactivate(address=self.unresolved_address) # Iterate through the outstanding responses, and if any correspond # to COMMIT requests then raise an error to signal that we are # unable to confirm that the COMMIT completed successfully. for response in self.responses: if isinstance(response, CommitResponse): if error: raise IncompleteCommit(message) from error else: raise IncompleteCommit(message) if direct_driver: if error: raise ServiceUnavailable(message) from error else: raise ServiceUnavailable(message) else: if error: raise SessionExpired(message) from error else: raise SessionExpired(message)
def acquire(self, access_mode=None, timeout=None, database=None): if access_mode not in (WRITE_ACCESS, READ_ACCESS): raise ClientError( "Non valid 'access_mode'; {}".format(access_mode)) if not timeout: raise ClientError( "'timeout' must be a float larger than 0; {}".format(timeout)) from neo4j.api import check_access_mode access_mode = check_access_mode(access_mode) while True: try: # Get an address for a connection that have the fewest in-use connections. address = self._select_address(access_mode=access_mode, database=database) log.debug( "[#0000] C: <ACQUIRE ADDRESS> database=%r address=%r", database, address) except (ReadServiceUnavailable, WriteServiceUnavailable) as err: raise SessionExpired( "Failed to obtain connection towards '%s' server." % access_mode) from err try: connection = self._acquire( address, timeout=timeout) # should always be a resolved address except ServiceUnavailable: self.deactivate(address=address) else: return connection
def acquire(self, access_mode=None, timeout=None): from neo4j.api import check_access_mode access_mode = check_access_mode(access_mode) while True: try: address = self._select_address(access_mode) except (ReadServiceUnavailable, WriteServiceUnavailable) as err: raise SessionExpired("Failed to obtain connection towards '%s' server." % access_mode) from err try: connection = self._acquire(address, timeout=timeout) # should always be a resolved address except ServiceUnavailable: self.deactivate(address) else: return connection
def acquire(self, *, access_mode, timeout, database): from neo4j.api import check_access_mode access_mode = check_access_mode(access_mode) while True: try: # Get an address for a connection that have the fewest in-use connections. address = self._select_address(access_mode=access_mode, database=database) log.debug("[#0000] C: <ACQUIRE ADDRESS> database=%r address=%r", database, address) except (ReadServiceUnavailable, WriteServiceUnavailable) as err: raise SessionExpired("Failed to obtain connection towards '%s' server." % access_mode) from err try: connection = self._acquire(address, timeout=timeout) # should always be a resolved address except ServiceUnavailable: self.deactivate(address=address) else: return connection
def acquire(self, access_mode=None, timeout=None): from neo4j import READ_ACCESS, WRITE_ACCESS if access_mode is None: access_mode = WRITE_ACCESS if access_mode not in (READ_ACCESS, WRITE_ACCESS): raise ValueError("Unsupported access mode {}".format(access_mode)) while True: try: address = self._select_address(access_mode) except Neo4jAvailabilityError as err: raise SessionExpired( "Failed to obtain connection towards '%s' server." % access_mode) from err try: connection = self._acquire( address, timeout=timeout) # should always be a resolved address except ServiceUnavailable: self.deactivate(address) else: return connection