Skip to content

Commit 50a7f27

Browse files
fix: remove dead _in_use set from ConnectionPool
The _in_use set was written to (add/discard) but never read anywhere in the codebase. It was left behind after #080 removed force-closing of in-use connections from close(). Remove the dead code to reduce confusion and maintenance burden. Fixes #105 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ec7b3eb commit 50a7f27

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

src/dqliteclient/pool.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ def __init__(
5757

5858
self._cluster = ClusterClient.from_addresses(addresses, timeout=timeout)
5959
self._pool: asyncio.Queue[DqliteConnection] = asyncio.Queue(maxsize=max_size)
60-
self._in_use: set[DqliteConnection] = set()
6160
self._size = 0
6261
self._lock = asyncio.Lock()
6362
self._closed = False
@@ -144,11 +143,9 @@ async def acquire(self) -> AsyncIterator[DqliteConnection]:
144143
self._size -= 1
145144
conn = await self._create_connection()
146145

147-
self._in_use.add(conn)
148146
try:
149147
yield conn
150148
except BaseException:
151-
self._in_use.discard(conn)
152149
if conn.is_connected and not self._closed:
153150
# Connection is healthy — user code raised a non-connection error.
154151
# Return it to the pool instead of destroying it.
@@ -166,7 +163,6 @@ async def acquire(self) -> AsyncIterator[DqliteConnection]:
166163
self._size -= 1
167164
raise
168165
else:
169-
self._in_use.discard(conn)
170166
await self._release(conn)
171167

172168
async def _release(self, conn: DqliteConnection) -> None:

tests/test_pool.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,13 @@ async def slow_close():
561561
f"CancelledError during close() skipped _size decrement."
562562
)
563563

564+
async def test_pool_has_no_in_use_set(self) -> None:
565+
"""Pool should not maintain a dead _in_use set (removed as dead code)."""
566+
pool = ConnectionPool(["localhost:9001"])
567+
assert not hasattr(pool, "_in_use"), (
568+
"Pool._in_use set should have been removed — it was dead code (written but never read)"
569+
)
570+
564571

565572
class TestConnectionPoolIntegration:
566573
"""Integration tests requiring mocked connections."""

0 commit comments

Comments
 (0)