Skip to content

Commit a805f38

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

31 files changed

+637
-341
lines changed

docs/source/api.rst

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,11 @@ 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`
167+
+ :ref:`connection-timeout-ref`
166168
+ :ref:`encrypted-ref`
167169
+ :ref:`keep-alive-ref`
168170
+ :ref:`max-connection-lifetime-ref`
@@ -175,12 +177,52 @@ Additional configuration can be provided via the :class:`neo4j.Driver` construct
175177
+ :ref:`user-agent-ref`
176178

177179

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

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

185227
:Type: ``float``
186228
:Default: ``60.0``
@@ -190,7 +232,11 @@ Since the process of acquiring a connection may involve creating a new connectio
190232

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

195241
:Type: ``float``
196242
:Default: ``30.0``
@@ -224,7 +270,6 @@ Specify whether TCP keep-alive should be enabled.
224270

225271
``max_connection_lifetime``
226272
---------------------------
227-
228273
The maximum duration in seconds that the driver will keep a connection for before being removed from the pool.
229274

230275
: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)