From f103d1b0d1920260a6e46d408ffb44aa735e0579 Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 24 Aug 2020 11:23:04 +0200 Subject: [PATCH] cherry pick propagate connection error to defunct function (#466) --- neo4j/io/_bolt3.py | 17 ++++++++++++++--- neo4j/io/_bolt4x0.py | 17 ++++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/neo4j/io/_bolt3.py b/neo4j/io/_bolt3.py index cbd63fae..456a28d3 100644 --- a/neo4j/io/_bolt3.py +++ b/neo4j/io/_bolt3.py @@ -343,6 +343,8 @@ def _set_defunct(self, error=None): message = ("Failed to read from defunct connection {!r} ({!r})".format( self.unresolved_address, self.server_info.address)) + 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 @@ -357,12 +359,21 @@ def _set_defunct(self, error=None): # unable to confirm that the COMMIT completed successfully. for response in self.responses: if isinstance(response, CommitResponse): - raise BoltIncompleteCommitError(message, address=None) + if error: + raise BoltIncompleteCommitError(message, address=None) from error + else: + raise BoltIncompleteCommitError(message, address=None) if direct_driver: - raise ServiceUnavailable(message) + if error: + raise ServiceUnavailable(message) from error + else: + raise ServiceUnavailable(message) else: - raise SessionExpired(message) + if error: + raise SessionExpired(message) from error + else: + raise SessionExpired(message) def timedout(self): return 0 <= self._max_connection_lifetime <= perf_counter() - self._creation_timestamp diff --git a/neo4j/io/_bolt4x0.py b/neo4j/io/_bolt4x0.py index ac3d73e1..b119067e 100644 --- a/neo4j/io/_bolt4x0.py +++ b/neo4j/io/_bolt4x0.py @@ -347,6 +347,8 @@ def _set_defunct(self, error=None): message = ("Failed to read from defunct connection {!r} ({!r})".format( self.unresolved_address, self.server_info.address)) + 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 @@ -361,12 +363,21 @@ def _set_defunct(self, error=None): # unable to confirm that the COMMIT completed successfully. for response in self.responses: if isinstance(response, CommitResponse): - raise BoltIncompleteCommitError(message, address=None) + if error: + raise BoltIncompleteCommitError(message, address=None) from error + else: + raise BoltIncompleteCommitError(message, address=None) if direct_driver: - raise ServiceUnavailable(message) + if error: + raise ServiceUnavailable(message) from error + else: + raise ServiceUnavailable(message) else: - raise SessionExpired(message) + if error: + raise SessionExpired(message) from error + else: + raise SessionExpired(message) def timedout(self): return 0 <= self._max_connection_lifetime <= perf_counter() - self._creation_timestamp