Skip to content

Commit e155e15

Browse files
fix: validate timeout is positive in connection, pool, and cluster
A timeout of 0 or negative makes every I/O operation fail immediately with a confusing TimeoutError. Now raises ValueError with a clear message at construction time. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7cc216f commit e155e15

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

src/dqliteclient/cluster.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ def __init__(
2424
node_store: Store for cluster node information
2525
timeout: Connection timeout in seconds
2626
"""
27+
if timeout <= 0:
28+
raise ValueError(f"timeout must be positive, got {timeout}")
2729
self._node_store = node_store
2830
self._timeout = timeout
2931

src/dqliteclient/connection.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ def __init__(
6060
database: Database name to open
6161
timeout: Connection timeout in seconds
6262
"""
63+
if timeout <= 0:
64+
raise ValueError(f"timeout must be positive, got {timeout}")
6365
self._address = address
6466
self._database = database
6567
self._timeout = timeout

src/dqliteclient/pool.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def __init__(
4040
raise ValueError(
4141
f"min_size ({min_size}) must not exceed max_size ({max_size})"
4242
)
43+
if timeout <= 0:
44+
raise ValueError(f"timeout must be positive, got {timeout}")
4345

4446
self._addresses = addresses
4547
self._database = database

tests/test_connection.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ def test_ipv6_no_port_raises(self) -> None:
4949

5050

5151
class TestDqliteConnection:
52+
def test_zero_timeout_raises(self) -> None:
53+
with pytest.raises(ValueError, match="timeout must be positive"):
54+
DqliteConnection("localhost:9001", timeout=0)
55+
56+
def test_negative_timeout_raises(self) -> None:
57+
with pytest.raises(ValueError, match="timeout must be positive"):
58+
DqliteConnection("localhost:9001", timeout=-1)
59+
5260
def test_init(self) -> None:
5361
conn = DqliteConnection("localhost:9001", database="test", timeout=5.0)
5462
assert conn.address == "localhost:9001"

0 commit comments

Comments
 (0)