Skip to content

Commit 3ab2e6e

Browse files
authored
Improve logging around connection errors (#594)
+ don't try to reset broken connections when releasing back into pool
1 parent 4b9ad52 commit 3ab2e6e

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
@@ -342,7 +342,7 @@ def open(cls, address, *, auth=None, timeout=None, routing_context=None, **pool_
342342
from neo4j.io._bolt4 import Bolt4x4
343343
bolt_cls = Bolt4x4
344344
else:
345-
log.debug("[#%04X] S: <CLOSE>", s.getpeername()[1])
345+
log.debug("[#%04X] S: <CLOSE>", s.getsockname()[1])
346346
_close_socket(s)
347347

348348
supported_versions = Bolt.protocol_handlers().keys()
@@ -548,7 +548,7 @@ def _set_defunct(self, message, error=None, silent=False):
548548
direct_driver = isinstance(self.pool, BoltPool)
549549

550550
if error:
551-
log.error(str(error))
551+
log.debug("[#%04X] %s", self.socket.getsockname()[1], error)
552552
log.error(message)
553553
# We were attempting to receive data but the connection
554554
# has unexpectedly terminated. So, we need to close the
@@ -711,7 +711,9 @@ def release(self, *connections):
711711
"""
712712
with self.lock:
713713
for connection in connections:
714-
if not connection.is_reset:
714+
if not (connection.is_reset
715+
or connection.defunct()
716+
or connection.closed()):
715717
try:
716718
connection.reset()
717719
except (Neo4jError, DriverError, BoltError) as e:

0 commit comments

Comments
 (0)