Skip to content

[4.4] Fix #796: connection pool clogging up #803

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
merged 2 commits into from
Sep 19, 2022
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
6 changes: 3 additions & 3 deletions neo4j/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,9 +756,9 @@ def connection_creator():
+ self.connections_reservations[address])
can_create_new_connection = (infinite_pool_size
or pool_size < max_pool_size)
self.connections_reservations[address] += 1
if can_create_new_connection:
return connection_creator
if can_create_new_connection:
self.connections_reservations[address] += 1
return connection_creator

def _acquire(self, address, deadline):

Expand Down
27 changes: 27 additions & 0 deletions tests/unit/io/test_neo4j_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
RoutingConfig,
WorkspaceConfig
)
from neo4j._deadline import Deadline
from neo4j.exceptions import (
ServiceUnavailable,
SessionExpired
Expand Down Expand Up @@ -271,3 +272,29 @@ def test_failing_opener_leaves_connections_in_use_alone(opener):
pool.acquire(READ_ACCESS, 30, 60, "test_db", None)

assert not cx1.closed()


def test__acquire_new_later_with_room(opener):
config = PoolConfig()
config.max_connection_pool_size = 1
pool = Neo4jPool(
opener, config, WorkspaceConfig(), ROUTER_ADDRESS
)
assert pool.connections_reservations[READER_ADDRESS] == 0
creator = pool._acquire_new_later(READER_ADDRESS, Deadline(1))
assert pool.connections_reservations[READER_ADDRESS] == 1
assert callable(creator)


def test__acquire_new_later_without_room(opener):
config = PoolConfig()
config.max_connection_pool_size = 1
pool = Neo4jPool(
opener, config, WorkspaceConfig(), ROUTER_ADDRESS
)
_ = pool.acquire(READ_ACCESS, 30, 60, "test_db", None)
# pool is full now
assert pool.connections_reservations[READER_ADDRESS] == 0
creator = pool._acquire_new_later(READER_ADDRESS, Deadline(1))
assert pool.connections_reservations[READER_ADDRESS] == 0
assert creator is None