Skip to content

Commit 9e7c594

Browse files
fix: validate pool min_size/max_size to prevent silent hangs
ConnectionPool now rejects min_size > max_size, min_size < 0, and max_size < 1 with clear ValueError messages. Previously, min_size greater than max_size caused initialize() to hang forever because the internal queue would fill up. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3de2b21 commit 9e7c594

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/dqliteclient/pool.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ def __init__(
3232
max_size: Maximum connections allowed
3333
timeout: Connection timeout
3434
"""
35+
if min_size < 0:
36+
raise ValueError(f"min_size must be non-negative, got {min_size}")
37+
if max_size < 1:
38+
raise ValueError(f"max_size must be at least 1, got {max_size}")
39+
if min_size > max_size:
40+
raise ValueError(
41+
f"min_size ({min_size}) must not exceed max_size ({max_size})"
42+
)
43+
3544
self._addresses = addresses
3645
self._database = database
3746
self._min_size = min_size

tests/test_pool.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@
1010

1111

1212
class TestConnectionPool:
13+
def test_min_size_greater_than_max_size_raises(self) -> None:
14+
with pytest.raises(ValueError, match="min_size.*must not exceed.*max_size"):
15+
ConnectionPool(["localhost:9001"], min_size=5, max_size=2)
16+
17+
def test_negative_min_size_raises(self) -> None:
18+
with pytest.raises(ValueError, match="min_size.*non-negative"):
19+
ConnectionPool(["localhost:9001"], min_size=-1)
20+
21+
def test_zero_max_size_raises(self) -> None:
22+
with pytest.raises(ValueError, match="max_size.*at least 1"):
23+
ConnectionPool(["localhost:9001"], max_size=0)
24+
1325
def test_init(self) -> None:
1426
pool = ConnectionPool(
1527
["localhost:9001", "localhost:9002"],

0 commit comments

Comments
 (0)