Skip to content

Commit 8997e51

Browse files
Add DEFAULT_MAX_TOTAL_ROWS / DEFAULT_MAX_CONTINUATION_FRAMES constants
The literals 10_000_000 and 100_000 appeared verbatim as default parameters across ~9 user-facing entry points in the client and dbapi packages. Promote both to named constants on the wire layer (the canonical home for governance bounds shared across packages) so a future tuning change has one place to edit. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent ff93495 commit 8997e51

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

src/dqlitewire/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
from dqlitewire.buffer import ReadBuffer, WriteBuffer
4242
from dqlitewire.codec import MessageDecoder, MessageEncoder, decode_message, encode_message
4343
from dqlitewire.constants import (
44+
DEFAULT_MAX_CONTINUATION_FRAMES,
45+
DEFAULT_MAX_TOTAL_ROWS,
4446
LEADER_ERROR_CODES,
4547
PROTOCOL_VERSION,
4648
PROTOCOL_VERSION_LEGACY,
@@ -80,6 +82,8 @@
8082

8183
__all__ = [
8284
"ContinuationError",
85+
"DEFAULT_MAX_CONTINUATION_FRAMES",
86+
"DEFAULT_MAX_TOTAL_ROWS",
8387
"__version__",
8488
"DecodeError",
8589
"EncodeError",

src/dqlitewire/constants.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,18 @@ def primary_sqlite_code(code: int) -> int:
155155
TX_AUTO_ROLLBACK_PRIMARY_CODES: frozenset[int] = frozenset(
156156
{SQLITE_ABORT, SQLITE_INTERRUPT, SQLITE_IOERR, SQLITE_CORRUPT, SQLITE_FULL}
157157
)
158+
159+
160+
# Cumulative-row cap for a single SELECT result spanning multiple
161+
# continuation frames. The default protects against unbounded memory
162+
# growth on a maliciously slow-drip server while staying well above
163+
# any realistic legitimate result set. Forwarded to every
164+
# :class:`DqliteConnection` the public ``connect()`` /
165+
# ``ConnectionPool`` / dbapi ``connect()`` entry points hand out.
166+
DEFAULT_MAX_TOTAL_ROWS = 10_000_000
167+
168+
# Per-query continuation-frame cap. Complements
169+
# ``DEFAULT_MAX_TOTAL_ROWS``: a server sending one row per frame can
170+
# inflict O(n) Python decode work where n is the row cap; the frame
171+
# cap bounds that work even when the row cap is large.
172+
DEFAULT_MAX_CONTINUATION_FRAMES = 100_000

0 commit comments

Comments
 (0)