|
2 | 2 |
|
3 | 3 | import asyncio |
4 | 4 | import contextlib |
| 5 | +import logging |
5 | 6 | from collections.abc import AsyncIterator, Sequence |
6 | 7 | from contextlib import asynccontextmanager |
7 | 8 | from typing import Any |
|
12 | 13 | from dqliteclient.node_store import NodeStore |
13 | 14 | from dqliteclient.protocol import _validate_max_total_rows |
14 | 15 |
|
| 16 | +logger = logging.getLogger(__name__) |
| 17 | + |
15 | 18 |
|
16 | 19 | def _socket_looks_dead(conn: DqliteConnection) -> bool: |
17 | 20 | """Best-effort local detection of a half-closed TCP socket. |
@@ -290,16 +293,33 @@ async def _reset_connection(self, conn: DqliteConnection) -> bool: |
290 | 293 |
|
291 | 294 | Returns True if the connection is clean and can be reused, |
292 | 295 | False if it should be destroyed. |
| 296 | +
|
| 297 | + If ROLLBACK raises, the connection's transaction state is |
| 298 | + unknowable from the client's side — the wire request may have |
| 299 | + been half-sent, or delivered but not acknowledged. The pool |
| 300 | + therefore drops the connection; the dqlite cluster's Raft log |
| 301 | + eventually reclaims any uncommitted work from the terminated |
| 302 | + session. A DEBUG log entry is emitted to help operators |
| 303 | + diagnose churning pools. |
293 | 304 | """ |
294 | 305 | if conn._in_transaction: |
295 | 306 | # Cheap pre-write liveness check: if the transport is already |
296 | 307 | # closing or the reader has seen EOF, ROLLBACK would stall on |
297 | 308 | # _read_data until self._timeout. Bail fast instead. |
298 | 309 | if _socket_looks_dead(conn): |
| 310 | + logger.debug( |
| 311 | + "pool: dropping connection %s (socket looks dead before ROLLBACK)", |
| 312 | + conn._address, |
| 313 | + ) |
299 | 314 | return False |
300 | 315 | try: |
301 | 316 | await conn.execute("ROLLBACK") |
302 | | - except BaseException: |
| 317 | + except BaseException as exc: |
| 318 | + logger.debug( |
| 319 | + "pool: dropping connection %s after ROLLBACK failure: %r", |
| 320 | + conn._address, |
| 321 | + exc, |
| 322 | + ) |
303 | 323 | return False |
304 | 324 | conn._in_transaction = False |
305 | 325 | conn._tx_owner = None |
|
0 commit comments