Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 60 additions & 5 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ Driver Configuration

Additional configuration can be provided via the :class:`neo4j.Driver` constructor.


+ :ref:`session-connection-timeout-ref`
+ :ref:`update-routing-table-timeout-ref`
+ :ref:`connection-acquisition-timeout-ref`
+ :ref:`connection-timeout-ref`
+ :ref:`encrypted-ref`
Expand All @@ -175,12 +176,63 @@ Additional configuration can be provided via the :class:`neo4j.Driver` construct
+ :ref:`user-agent-ref`


.. _session-connection-timeout-ref:

``session_connection_timeout``
------------------------------
The maximum amount of time in seconds the session will wait when trying to
establish a usable read/write connection to the remote host.
This encompasses *everything* that needs to happen for this, including,
if necessary, updating the routing table, fetching a connection from the pool,
and, if necessary fully establishing a new connection with the reader/writer.

Since this process may involve updating the routing table, acquiring a
connection from the pool, or establishing a new connection, it should be chosen
larger than :ref:`update-routing-table-timeout-ref`,
:ref:`connection-acquisition-timeout-ref`, and :ref:`connection-timeout-ref`.

:Type: ``float``
:Default: ``120.0``

.. versionadded:: 4.4.5

.. versionchanged:: 5.0

The default value was changed from ``float("inf")`` to ``120.0``.


.. _update-routing-table-timeout-ref:

``update_routing_table_timeout``
--------------------------------
The maximum amount of time in seconds the driver will attempt to fetch a new
routing table. This encompasses *everything* that needs to happen for this,
including fetching connections from the pool, performing handshakes, and
requesting and receiving a fresh routing table.

Since this process may involve acquiring a connection from the pool, or
establishing a new connection, it should be chosen larger than
:ref:`connection-acquisition-timeout-ref` and :ref:`connection-timeout-ref`.

This setting only has an effect for :ref:`neo4j-driver-ref`, but not for
:ref:`bolt-driver-ref` as it does no routing at all.

:Type: ``float``
:Default: ``90.0``

.. versionadded:: 4.4.5


.. _connection-acquisition-timeout-ref:

``connection_acquisition_timeout``
----------------------------------
The maximum amount of time in seconds a session will wait when requesting a connection from the connection pool.
Since the process of acquiring a connection may involve creating a new connection, ensure that the value of this configuration is higher than the configured :ref:`connection-timeout-ref`.
The maximum amount of time in seconds the driver will wait to either acquire an
idle connection from the pool (including potential liveness checks) or create a
new connection when the pool is not full and all existing connection are in use.

Since this process may involve opening a new connection including handshakes,
it should be chosen larger than :ref:`connection-timeout-ref`.

:Type: ``float``
:Default: ``60.0``
Expand All @@ -190,7 +242,11 @@ Since the process of acquiring a connection may involve creating a new connectio

``connection_timeout``
----------------------
The maximum amount of time in seconds to wait for a TCP connection to be established.
The maximum amount of time in seconds to wait for a TCP connection to be
established.

This *does not* include any handshake(s), or authentication required before the
connection can be used to perform database related work.

:Type: ``float``
:Default: ``30.0``
Expand Down Expand Up @@ -224,7 +280,6 @@ Specify whether TCP keep-alive should be enabled.

``max_connection_lifetime``
---------------------------

The maximum duration in seconds that the driver will keep a connection for before being removed from the pool.

:Type: ``float``
Expand Down
11 changes: 3 additions & 8 deletions neo4j/_async/io/_bolt.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ async def ping(cls, address, *, timeout=None, **config):
except (ServiceUnavailable, SessionExpired, BoltHandshakeError):
return None
else:
AsyncBoltSocket.close_socket(s)
await AsyncBoltSocket.close_socket(s)
return protocol_version

@classmethod
Expand Down Expand Up @@ -357,11 +357,6 @@ def time_remaining():
connection.socket.set_deadline(time_remaining())
try:
await connection.hello()
except SocketDeadlineExceeded as e:
# connection._defunct = True
raise ServiceUnavailable(
"Timeout during initial handshake occurred"
) from e
finally:
connection.socket.set_deadline(None)
except Exception:
Expand Down Expand Up @@ -484,7 +479,7 @@ async def reset(self):

@abc.abstractmethod
def goodbye(self):
"""Append a GOODBYE message to the outgoing queued."""
"""Append a GOODBYE message to the outgoing queue."""
pass

def _append(self, signature, fields=(), response=None):
Expand Down Expand Up @@ -594,7 +589,7 @@ async def _set_defunct(self, message, error=None, silent=False):
direct_driver = isinstance(self.pool, AsyncBoltPool)

if error:
log.debug("[#%04X] %s", self.socket.getsockname()[1], error)
log.debug("[#%04X] %r", self.socket.getsockname()[1], error)
log.error(message)
# We were attempting to receive data but the connection
# has unexpectedly terminated. So, we need to close the
Expand Down
3 changes: 2 additions & 1 deletion neo4j/_async/io/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from struct import pack as struct_pack

from ..._async_compat.util import AsyncUtil
from ..._exceptions import SocketDeadlineExceeded
from ...exceptions import (
Neo4jError,
ServiceUnavailable,
Expand Down Expand Up @@ -70,7 +71,7 @@ async def _yield_messages(self, sock):
# Reset for new message
unpacker.reset()

except (OSError, socket.timeout) as error:
except (OSError, socket.timeout, SocketDeadlineExceeded) as error:
await AsyncUtil.callback(self.on_error, error)

async def pop(self):
Expand Down
Loading