From f51673878e8d2634f2eb5da2a10f737ad69e47b1 Mon Sep 17 00:00:00 2001 From: Andrew Brookins Date: Sat, 24 Jul 2021 07:13:40 -0700 Subject: [PATCH 1/4] Add _lock to BlockingConnectionPool Fixes #1047. --- aioredis/connection.py | 1 + tests/test_connection_pool.py | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/aioredis/connection.py b/aioredis/connection.py index 95b5a7abd..0506170f6 100644 --- a/aioredis/connection.py +++ b/aioredis/connection.py @@ -1488,6 +1488,7 @@ def __init__( self.queue_class = queue_class self.timeout = timeout self._connections: List[Connection] + self._lock = asyncio.Lock() super().__init__( connection_class=connection_class, max_connections=max_connections, diff --git a/tests/test_connection_pool.py b/tests/test_connection_pool.py index e428d8711..1931e2048 100644 --- a/tests/test_connection_pool.py +++ b/tests/test_connection_pool.py @@ -24,6 +24,9 @@ def __init__(self, **kwargs): async def connect(self): pass + async def disconnect(self): + pass + async def can_read(self, timeout: float = 0): return False @@ -122,6 +125,13 @@ async def test_connection_creation(self, master_host): assert isinstance(connection, DummyConnection) assert connection.kwargs == connection_kwargs + async def test_disconnect(self, master_host): + """A regression test for #1047""" + connection_kwargs = {"foo": "bar", "biz": "baz", "host": master_host} + pool = self.get_pool(connection_kwargs=connection_kwargs) + await pool.get_connection("_") + await pool.disconnect() + async def test_multiple_connections(self, master_host): connection_kwargs = {"host": master_host} pool = self.get_pool(connection_kwargs=connection_kwargs) From 4ace7e7209ee7a2e11d6f18742f18382418787d8 Mon Sep 17 00:00:00 2001 From: Andrew Brookins Date: Thu, 29 Jul 2021 06:23:47 -0700 Subject: [PATCH 2/4] Instantiate _lock in ConnectionPool --- CHANGES/1068.bugfix | 1 + aioredis/connection.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 CHANGES/1068.bugfix diff --git a/CHANGES/1068.bugfix b/CHANGES/1068.bugfix new file mode 100644 index 000000000..f9082d49b --- /dev/null +++ b/CHANGES/1068.bugfix @@ -0,0 +1 @@ +Adds a lock diff --git a/aioredis/connection.py b/aioredis/connection.py index 0506170f6..8816d60cf 100644 --- a/aioredis/connection.py +++ b/aioredis/connection.py @@ -1267,7 +1267,7 @@ def __init__( # will notice the first thread already did the work and simply # release the lock. self._fork_lock = threading.Lock() - self._lock: asyncio.Lock + self._lock = asyncio.Lock() self._created_connections: int self._available_connections: List[Connection] self._in_use_connections: Set[Connection] From ae92a3f3d62cf867e6a6478ae68cdc1fb7550b66 Mon Sep 17 00:00:00 2001 From: Andrew Brookins Date: Thu, 29 Jul 2021 06:24:58 -0700 Subject: [PATCH 3/4] Continue to rely on super to create _lock --- aioredis/connection.py | 1 - 1 file changed, 1 deletion(-) diff --git a/aioredis/connection.py b/aioredis/connection.py index 8816d60cf..0fdf4590a 100644 --- a/aioredis/connection.py +++ b/aioredis/connection.py @@ -1488,7 +1488,6 @@ def __init__( self.queue_class = queue_class self.timeout = timeout self._connections: List[Connection] - self._lock = asyncio.Lock() super().__init__( connection_class=connection_class, max_connections=max_connections, From 3e9d7105b3818e78038f9bf48449c79587c13688 Mon Sep 17 00:00:00 2001 From: Andrew Brookins Date: Thu, 29 Jul 2021 11:21:39 -0700 Subject: [PATCH 4/4] Update CHANGES/1068.bugfix Co-authored-by: Andrew Chen Wang <60190294+Andrew-Chen-Wang@users.noreply.github.com> --- CHANGES/1068.bugfix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES/1068.bugfix b/CHANGES/1068.bugfix index f9082d49b..81593eb93 100644 --- a/CHANGES/1068.bugfix +++ b/CHANGES/1068.bugfix @@ -1 +1 @@ -Adds a lock +Adds a lock to ``aioredis.connection.ConnectionPool``