Skip to content

Don't send routing context in HELLO message for direct connections #515

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

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
2 changes: 1 addition & 1 deletion neo4j/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,4 +308,4 @@ class CertificateConfigurationError(ConfigurationError):

class UnsupportedServerProduct(Exception):
""" Raised when an unsupported server product is detected.
"""
"""
28 changes: 11 additions & 17 deletions neo4j/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,33 +560,28 @@ def close(self):
class BoltPool(IOPool):

@classmethod
def open(cls, address, *, auth, pool_config, workspace_config, routing_context=None):
def open(cls, address, *, auth, pool_config, workspace_config):
"""Create a new BoltPool

:param address:
:param auth:
:param pool_config:
:param workspace_config:
:param routing_context:
:return: BoltPool
"""

if routing_context is None:
routing_context = {}
elif "address" in routing_context:
raise ConfigurationError("The key 'address' is reserved for routing context.")
routing_context["address"] = str(address)

def opener(addr, timeout):
return Bolt.open(addr, auth=auth, timeout=timeout, routing_context=routing_context, **pool_config)
return Bolt.open(
addr, auth=auth, timeout=timeout, routing_context=None,
**pool_config
)

pool = cls(opener, pool_config, workspace_config, routing_context, address)
pool = cls(opener, pool_config, workspace_config, address)
return pool

def __init__(self, opener, pool_config, workspace_config, routing_context, address):
def __init__(self, opener, pool_config, workspace_config, address):
super(BoltPool, self).__init__(opener, pool_config, workspace_config)
self.address = address
self.routing_context = routing_context

def __repr__(self):
return "<{} address={!r}>".format(self.__class__.__name__, self.address)
Expand Down Expand Up @@ -621,26 +616,25 @@ def open(cls, *addresses, auth, pool_config, workspace_config, routing_context=N
routing_context["address"] = str(address)

def opener(addr, timeout):
return Bolt.open(addr, auth=auth, timeout=timeout, routing_context=routing_context, **pool_config)
return Bolt.open(addr, auth=auth, timeout=timeout,
routing_context=routing_context, **pool_config)

pool = cls(opener, pool_config, workspace_config, routing_context, address)
pool = cls(opener, pool_config, workspace_config, address)
return pool

def __init__(self, opener, pool_config, workspace_config, routing_context, address):
def __init__(self, opener, pool_config, workspace_config, address):
"""

:param opener:
:param pool_config:
:param workspace_config:
:param routing_context: Dictionary with routing information
:param addresses:
"""
super(Neo4jPool, self).__init__(opener, pool_config, workspace_config)
# Each database have a routing table, the default database is a special case.
log.debug("[#0000] C: <NEO4J POOL> routing address %r", address)
self.address = address
self.routing_tables = {workspace_config.database: RoutingTable(database=workspace_config.database, routers=[address])}
self.routing_context = routing_context
self.refresh_lock = Lock()

def __repr__(self):
Expand Down
6 changes: 4 additions & 2 deletions neo4j/io/_bolt4.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,12 @@ def get_base_headers(self):
enables server-side routing to propagate the same behaviour
through its driver.
"""
return {
headers = {
"user_agent": self.user_agent,
"routing": self.routing_context,
}
if self.routing_context is not None:
headers["routing"] = self.routing_context
return headers


class Bolt4x2(Bolt4x1):
Expand Down
4 changes: 2 additions & 2 deletions tests/stub/scripts/v4x1/empty_explicit_hello_goodbye.script
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
!: BOLT 4.1
!: PORT 9001

C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test", "routing": {"address": "localhost:9001"}}
C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test"}
S: SUCCESS {"server": "Neo4j/4.1.0", "connection_id": "123e4567-e89b-12d3-a456-426655440000"}
C: GOODBYE
S: <EXIT>
S: <EXIT>
2 changes: 1 addition & 1 deletion tests/stub/scripts/v4x1/return_1_noop_port_9001.script
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
!: AUTO RESET
!: PORT 9001

C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test", "routing": {"address": "localhost:9001"}}
C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test"}
S: SUCCESS {"server": "Neo4j/4.1.0", "connection_id": "123e4567-e89b-12d3-a456-426655440000"}
C: RUN "RETURN 1 AS x" {} {"mode": "r"}
PULL {"n": 2}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
!: BOLT 4.1
!: PORT 9001

C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test", "routing": {"address": "localhost:9001"}}
C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test"}
S: SUCCESS {"server": "Bogus/4.1.0", "connection_id": "123e4567-e89b-12d3-a456-426655440000"}
C: RUN "RETURN 1 AS x" {} {"mode": "r"}
PULL {"n": -1}
S: SUCCESS {"fields": ["x"]}
RECORD [1]
SUCCESS {"bookmark": "neo4j:bookmark-test-1", "type": "r", "t_last": 5, "db": "neo4j"}
SUCCESS {"bookmark": "neo4j:bookmark-test-1", "type": "r", "t_last": 5, "db": "neo4j"}
4 changes: 2 additions & 2 deletions tests/stub/scripts/v4x2/empty_explicit_hello_goodbye.script
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
!: BOLT 4.2
!: PORT 9001

C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test", "routing": {"address": "localhost:9001"}}
C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test"}
S: SUCCESS {"server": "Neo4j/4.2.0", "connection_id": "123e4567-e89b-12d3-a456-426655440000"}
C: GOODBYE
S: <EXIT>
S: <EXIT>
2 changes: 1 addition & 1 deletion tests/stub/scripts/v4x2/return_1_noop_port_9001.script
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
!: AUTO RESET
!: PORT 9001

C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test", "routing": {"address": "localhost:9001"}}
C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test"}
S: SUCCESS {"server": "Neo4j/4.2.0", "connection_id": "123e4567-e89b-12d3-a456-426655440000"}
C: RUN "RETURN 1 AS x" {} {"mode": "r"}
PULL {"n": 2}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
!: BOLT 4.2
!: PORT 9001

C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test", "routing": {"address": "localhost:9001"}}
C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test"}
S: SUCCESS {"server": "Bogus/4.2.0", "connection_id": "123e4567-e89b-12d3-a456-426655440000"}
C: RUN "RETURN 1 AS x" {} {"mode": "r"}
PULL {"n": -1}
S: SUCCESS {"fields": ["x"]}
RECORD [1]
SUCCESS {"bookmark": "neo4j:bookmark-test-1", "type": "r", "t_last": 5, "db": "neo4j"}
SUCCESS {"bookmark": "neo4j:bookmark-test-1", "type": "r", "t_last": 5, "db": "neo4j"}