Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ See also https://github.com/neo4j/neo4j-python-driver/wiki for a full changelog.
- `neo4j.exceptions.UnsupportedServerProduct` if no common bolt protocol version could be negotiated with the server
(instead of internal `neo4j._exceptions.BoltHandshakeError`).
`UnsupportedServerProduct` is now a subclass of `ServiceUnavailable` (instead of `Exception` directly).
- `connection_acquisition_timeout` configuration option
- `ValueError` on invalid values (instead of `ClientError`)
- Consistently restrict the value to be strictly positive


## Version 5.28
Expand Down
23 changes: 18 additions & 5 deletions src/neo4j/_async/io/_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import abc
import asyncio
import logging
import math
import typing as t
from collections import (
defaultdict,
Expand Down Expand Up @@ -670,6 +671,7 @@ async def acquire(
# The access_mode and database is not needed for a direct connection,
# it's just there for consistency.
access_mode = check_access_mode(access_mode)
_check_acquisition_timeout(timeout)
log.debug(
"[#0000] _: <POOL> acquire direct connection, "
"access_mode=%r, database=%r",
Expand Down Expand Up @@ -972,6 +974,7 @@ async def update_routing_table(

:raise neo4j.exceptions.ServiceUnavailable:
"""
_check_acquisition_timeout(acquisition_timeout)
async with self.refresh_lock:
routing_table = await self.get_routing_table(database)
if routing_table is not None:
Expand Down Expand Up @@ -1149,11 +1152,7 @@ async def acquire(
database_callback=None,
):
access_mode = check_access_mode(access_mode)
if not timeout:
# TODO: 6.0 - change this to be a ValueError
raise ClientError(
f"'timeout' must be a float larger than 0; {timeout}"
)
_check_acquisition_timeout(timeout)

target_database = database.name

Expand Down Expand Up @@ -1246,3 +1245,17 @@ async def on_write_failure(self, address, database):
if table is not None:
table.writers.discard(address)
log.debug("[#0000] _: <POOL> table=%r", self.routing_tables)


def _check_acquisition_timeout(timeout: object) -> None:
if not isinstance(timeout, (int, float)):
raise TypeError(
"Connection acquisition timeout must be a number, "
f"got {type(timeout)}"
)
if timeout <= 0:
raise ValueError(
f"Connection acquisition timeout must be > 0, got {timeout}"
)
if math.isnan(timeout):
raise ValueError("Connection acquisition timeout must not be NaN")
23 changes: 18 additions & 5 deletions src/neo4j/_sync/io/_pool.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion testkitbackend/_async/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,9 +981,15 @@ async def forced_routing_table_update(backend, data):
driver = backend.drivers[driver_id]
database = data["database"]
bookmarks = data["bookmarks"]
acquisition_timeout = (
driver._default_workspace_config.connection_acquisition_timeout
)
async with driver._pool.refresh_lock:
await driver._pool.update_routing_table(
database=database, imp_user=None, bookmarks=bookmarks
database=database,
imp_user=None,
bookmarks=bookmarks,
acquisition_timeout=acquisition_timeout,
)
await backend.send_response("Driver", {"id": driver_id})

Expand Down
8 changes: 7 additions & 1 deletion testkitbackend/_sync/requests.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.