Skip to content

Commit 5a70a26

Browse files
fix: use correct SQLite extended error codes for leader detection
The previous values {0, 4097} came from Go client internals, not the wire protocol. The C dqlite server sends SQLite extended error codes: - SQLITE_IOERR_NOT_LEADER = 10250 (SQLITE_IOERR | (40 << 8)) - SQLITE_IOERR_LEADERSHIP_LOST = 10506 (SQLITE_IOERR | (41 << 8)) Code 0 actually means "empty statement", not "not leader", so the old constant would invalidate connections on empty SQL. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ecfaf78 commit 5a70a26

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

src/dqliteclient/connection.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
from dqliteclient.exceptions import DqliteConnectionError, OperationalError, ProtocolError
99
from dqliteclient.protocol import DqliteProtocol
1010

11-
# dqlite error codes that indicate a leader change
12-
_LEADER_ERROR_CODES = {0, 4097} # ErrNotLeader, ErrLeadershipLost
11+
# dqlite error codes that indicate a leader change (SQLite extended error codes)
12+
# SQLITE_IOERR_NOT_LEADER = SQLITE_IOERR | (40 << 8) = 10250
13+
# SQLITE_IOERR_LEADERSHIP_LOST = SQLITE_IOERR | (41 << 8) = 10506
14+
_LEADER_ERROR_CODES = {10250, 10506}
1315

1416

1517
def _parse_address(address: str) -> tuple[str, int]:

tests/test_connection.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,9 @@ async def test_not_leader_error_invalidates_connection(self) -> None:
428428

429429
assert conn.is_connected
430430

431-
# Server responds with "not leader" error (code 0)
432-
not_leader = FailureResponse(code=0, message="not leader").encode()
431+
# Server responds with "not leader" error
432+
# SQLITE_IOERR_NOT_LEADER = SQLITE_IOERR | (40 << 8) = 10250
433+
not_leader = FailureResponse(code=10250, message="not leader").encode()
433434
mock_reader.read.side_effect = [not_leader]
434435

435436
from dqliteclient.exceptions import OperationalError

0 commit comments

Comments
 (0)