Skip to content

Try all routers before giving up #529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
19 changes: 13 additions & 6 deletions neo4j/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,10 +754,13 @@ def update_routing_table_from(self, *routers, database=None,
"""
log.debug("Attempting to update routing table from {}".format(", ".join(map(repr, routers))))
for router in routers:
new_routing_table = self.fetch_routing_table(
address=router, timeout=self.pool_config.connection_timeout,
database=database, bookmarks=bookmarks
)
try:
new_routing_table = self.fetch_routing_table(
address=router, timeout=self.pool_config.connection_timeout,
database=database, bookmarks=bookmarks
)
Comment on lines +758 to +761
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this method always return None instead of raising an exception if anything goes wrong.

except BoltRoutingError:
continue
if new_routing_table is not None:
self.routing_tables[database].update(new_routing_table)
log.debug("[#0000] C: <UPDATE ROUTING TABLE> address={!r} ({!r})".format(router, self.routing_tables[database]))
Expand Down Expand Up @@ -786,8 +789,12 @@ def update_routing_table(self, *, database, bookmarks):
):
# Why is only the first initial routing address used?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pop initial router if in list and remove list comprehension further down.

return
if self.update_routing_table_from(*existing_routers, database=database,
bookmarks=bookmarks):
if self.update_routing_table_from(
*[r for r in existing_routers
if (not has_tried_initial_routers
or r != self.first_initial_routing_address)],
database=database, bookmarks=bookmarks
):
return

if (not has_tried_initial_routers
Expand Down
6 changes: 2 additions & 4 deletions tests/stub/test_routingdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@
)
from neo4j.exceptions import (
ServiceUnavailable,
ClientError,
TransientError,
SessionExpired,
ConfigurationError,
)
from neo4j._exceptions import (
BoltRoutingError,
BoltSecurityError,
)
from tests.stub.conftest import StubCluster
Expand Down Expand Up @@ -214,7 +212,7 @@ def test_cannot_discover_servers_on_non_router(driver_info, test_script):
def test_cannot_discover_servers_on_silent_router(driver_info, test_script):
# python -m pytest tests/stub/test_routingdriver.py -s -v -k test_cannot_discover_servers_on_silent_router
with StubCluster(test_script):
with pytest.raises(BoltRoutingError):
with pytest.raises(ServiceUnavailable, match="routing"):
with GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"]) as driver:
assert isinstance(driver, Neo4jDriver)
driver._pool.update_routing_table(database=None, bookmarks=None)
Expand Down Expand Up @@ -532,7 +530,7 @@ def test_should_serve_read_when_missing_writer(driver_info, test_scripts, test_r
def test_should_error_when_missing_reader(driver_info, test_script):
# python -m pytest tests/stub/test_routingdriver.py -s -v -k test_should_error_when_missing_reader
with StubCluster(test_script):
with pytest.raises(BoltRoutingError):
with pytest.raises(ServiceUnavailable, match="routing"):
with GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"]) as driver:
assert isinstance(driver, Neo4jDriver)
driver._pool.update_routing_table(database=None, bookmarks=None)
Expand Down