Skip to content

Commit 74e5739

Browse files
authored
Improve logging around connection errors (#595)
+ don't try to reset broken connections when releasing back into pool Backport of #594
1 parent 69c4d46 commit 74e5739

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

neo4j/io/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def open(cls, address, *, auth=None, timeout=None, routing_context=None, **pool_
335335
from neo4j.io._bolt4 import Bolt4x3
336336
connection = Bolt4x3(address, s, pool_config.max_connection_lifetime, auth=auth, user_agent=pool_config.user_agent, routing_context=routing_context)
337337
else:
338-
log.debug("[#%04X] S: <CLOSE>", s.getpeername()[1])
338+
log.debug("[#%04X] S: <CLOSE>", s.getsockname()[1])
339339
_close_socket(s)
340340

341341
supported_versions = Bolt.protocol_handlers().keys()
@@ -540,7 +540,7 @@ def _set_defunct(self, message, error=None, silent=False):
540540
direct_driver = isinstance(self.pool, BoltPool)
541541

542542
if error:
543-
log.error(str(error))
543+
log.debug("[#%04X] %s", self.socket.getsockname()[1], error)
544544
log.error(message)
545545
# We were attempting to receive data but the connection
546546
# has unexpectedly terminated. So, we need to close the
@@ -703,7 +703,9 @@ def release(self, *connections):
703703
"""
704704
with self.lock:
705705
for connection in connections:
706-
if not connection.is_reset:
706+
if not (connection.is_reset
707+
or connection.defunct()
708+
or connection.closed()):
707709
try:
708710
connection.reset()
709711
except (Neo4jError, DriverError, BoltError) as e:

0 commit comments

Comments
 (0)