Skip to content

Commit 723585f

Browse files
Validate timeout in Connection/AsyncConnection __init__
Cycle 8 — direct Connection(address, timeout=-1) / AsyncConnection calls bypassed the dqlitedbapi.connect() validation added earlier and silently stored invalid timeouts that caused hangs or stranger downstream errors. Both class constructors now reject non-finite and non-positive timeouts up front. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent f9754e9 commit 723585f

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/dqlitedbapi/aio/connection.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ def __init__(
2323
Args:
2424
address: Node address in "host:port" format
2525
database: Database name to open
26-
timeout: Connection timeout in seconds
26+
timeout: Connection timeout in seconds (positive, finite)
2727
"""
28+
import math
29+
30+
if not math.isfinite(timeout) or timeout <= 0:
31+
raise ValueError(f"timeout must be a positive finite number, got {timeout}")
2832
self._address = address
2933
self._database = database
3034
self._timeout = timeout

src/dqlitedbapi/connection.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,15 @@ def __init__(
7070
Args:
7171
address: Node address in "host:port" format
7272
database: Database name to open
73-
timeout: Connection timeout in seconds
73+
timeout: Connection timeout in seconds (must be positive
74+
and finite; validated here so direct ``Connection(...)``
75+
calls don't silently accept bad values that later
76+
produce hangs or stranger downstream errors)
7477
"""
78+
import math
79+
80+
if not math.isfinite(timeout) or timeout <= 0:
81+
raise ValueError(f"timeout must be a positive finite number, got {timeout}")
7582
self._address = address
7683
self._database = database
7784
self._timeout = timeout

0 commit comments

Comments
 (0)