Skip to content

Commit 43ddb35

Browse files
committed
Clean-up, refactoring, and documentation
1 parent 54a738b commit 43ddb35

31 files changed

+661
-341
lines changed

docs/source/api.rst

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ Driver Configuration
160160

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

163-
163+
+ :ref:`session-connection-timeout-ref`
164+
+ :ref:`update-routing-table-timeout-ref`
164165
+ :ref:`connection-acquisition-timeout-ref`
165166
+ :ref:`connection-timeout-ref`
166167
+ :ref:`encrypted-ref`
@@ -175,12 +176,55 @@ Additional configuration can be provided via the :class:`neo4j.Driver` construct
175176
+ :ref:`user-agent-ref`
176177

177178

179+
.. _session-connection-timeout-ref:
180+
181+
``session_connection_timeout``
182+
------------------------------
183+
The maximum amount of time in seconds the session will wait when trying to
184+
establish a usable read/write connection to the remote host.
185+
This encompasses *everything* that needs to happen for this, including,
186+
if necessary, updating the routing table, fetching a connection from the pool,
187+
and, if necessary fully establishing a new connection with the reader/writer.
188+
189+
Since this process may involve updating the routing table, acquiring a
190+
connection from the pool, or establishing a new connection, it should be chosen
191+
larger than :ref:`update-routing-table-timeout-ref`,
192+
:ref:`connection-acquisition-timeout-ref`, and :ref:`connection-timeout-ref`.
193+
194+
:Type: ``float``
195+
:Default: ``120.0``
196+
197+
198+
.. _update-routing-table_timeout-ref:
199+
200+
``update_routing_table_timeout``
201+
--------------------------------
202+
The maximum amount of time in seconds the driver will attempt to fetch a new
203+
routing table. This encompasses *everything* that needs to happen for this,
204+
including fetching connections from the pool, performing handshakes, and
205+
requesting and receiving a fresh routing table.
206+
207+
Since this process may involve acquiring a connection from the pool, or
208+
establishing a new connection, it should be chosen larger than
209+
:ref:`connection-acquisition-timeout-ref` and :ref:`connection-timeout-ref`.
210+
211+
This setting only has an effect for :ref:`neo4j-driver-ref`, but not for
212+
:ref:`bolt-driver-ref` as it does no routing at all.
213+
214+
:Type: ``float``
215+
:Default: ``90.0``
216+
217+
178218
.. _connection-acquisition-timeout-ref:
179219

180220
``connection_acquisition_timeout``
181221
----------------------------------
182-
The maximum amount of time in seconds a session will wait when requesting a connection from the connection pool.
183-
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`.
222+
The maximum amount of time in seconds the driver will wait to either acquire an
223+
idle connection from the pool (including potential liveness checks) or create a
224+
new connection when the pool is not full and all existing connection are in use.
225+
226+
Since this process may involve opening a new connection including handshakes,
227+
it should be chosen larger than :ref:`connection-timeout-ref`.
184228

185229
:Type: ``float``
186230
:Default: ``60.0``
@@ -190,7 +234,11 @@ Since the process of acquiring a connection may involve creating a new connectio
190234

191235
``connection_timeout``
192236
----------------------
193-
The maximum amount of time in seconds to wait for a TCP connection to be established.
237+
The maximum amount of time in seconds to wait for a TCP connection to be
238+
established.
239+
240+
This *does not* include any handshake(s), or authentication required before the
241+
connection can be used to perform database related work.
194242

195243
:Type: ``float``
196244
:Default: ``30.0``
@@ -224,7 +272,6 @@ Specify whether TCP keep-alive should be enabled.
224272

225273
``max_connection_lifetime``
226274
---------------------------
227-
228275
The maximum duration in seconds that the driver will keep a connection for before being removed from the pool.
229276

230277
:Type: ``float``

neo4j/_async/io/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,13 @@
2929
"AsyncNeo4jPool",
3030
"check_supported_server_product",
3131
"ConnectionErrorHandler",
32-
"time_remaining",
3332
]
3433

3534

3635
from ._bolt import AsyncBolt
3736
from ._common import (
3837
check_supported_server_product,
3938
ConnectionErrorHandler,
40-
time_remaining,
4139
)
4240
from ._pool import (
4341
AsyncBoltPool,

neo4j/_async/io/_bolt.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -357,12 +357,6 @@ def time_remaining():
357357
connection.socket.set_deadline(time_remaining())
358358
try:
359359
await connection.hello()
360-
except SocketDeadlineExceeded as e:
361-
# connection._defunct = True
362-
log.debug("[#%04X] S: <TIMEOUT>", connection.local_port)
363-
raise ServiceUnavailable(
364-
"Timeout during initial handshake occurred"
365-
) from e
366360
finally:
367361
connection.socket.set_deadline(None)
368362
except Exception:
@@ -595,7 +589,7 @@ async def _set_defunct(self, message, error=None, silent=False):
595589
direct_driver = isinstance(self.pool, AsyncBoltPool)
596590

597591
if error:
598-
log.debug("[#%04X] %s", self.socket.getsockname()[1], error)
592+
log.debug("[#%04X] %r", self.socket.getsockname()[1], error)
599593
log.error(message)
600594
# We were attempting to receive data but the connection
601595
# has unexpectedly terminated. So, we need to close the

neo4j/_async/io/_common.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
import logging
2222
import socket
2323
from struct import pack as struct_pack
24-
from time import perf_counter
2524

2625
from ..._async_compat.util import AsyncUtil
26+
from ..._exceptions import SocketDeadlineExceeded
2727
from ...exceptions import (
2828
Neo4jError,
2929
ServiceUnavailable,
@@ -39,13 +39,6 @@
3939
log = logging.getLogger("neo4j")
4040

4141

42-
def time_remaining(t0, timeout):
43-
if timeout is None:
44-
return None
45-
t = timeout - (perf_counter() - t0)
46-
return t if t > 0 else 0
47-
48-
4942
class AsyncMessageInbox:
5043

5144
def __init__(self, s, on_error):
@@ -78,7 +71,7 @@ async def _yield_messages(self, sock):
7871
# Reset for new message
7972
unpacker.reset()
8073

81-
except (OSError, socket.timeout) as error:
74+
except (OSError, socket.timeout, SocketDeadlineExceeded) as error:
8275
await AsyncUtil.callback(self.on_error, error)
8376

8477
async def pop(self):

0 commit comments

Comments
 (0)