Skip to content

Commit a05854a

Browse files
Add connection identity to the rollback-failure DEBUG log
The AsyncAdaptedConnection.close rollback-failure DEBUG log named the exception class but not the connection. In a pool of 20 async connections churning several pool events per second, that produces a stream of identical lines with no way to tell which adapter or which peer is misbehaving. Include id(self) and the peer address from the wrapped dbapi connection so operators can correlate log records to specific adapter instances and cluster nodes. id(self) is chosen over id(self._connection) because SQLAlchemy's pool tracks the outer adapter — that's the natural correlation handle. Peer address is looked up defensively via getattr(..., "address", None) so the log never fails on an adapter constructed in a test harness. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent cf38d1e commit a05854a

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

src/sqlalchemydqlite/aio.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,15 @@ def close(self) -> None:
243243
) as exc:
244244
# Silent suppression used to hide e.g. "leader flip
245245
# mid-rollback" from operators — a DEBUG line preserves the
246-
# diagnostic without masking or propagating.
246+
# diagnostic without masking or propagating. Include both
247+
# id(self) and the peer address so a noisy pool can be
248+
# correlated to specific adapter instances and nodes.
249+
peer = getattr(self._connection, "address", None)
247250
logger.debug(
248-
"AsyncAdaptedConnection.close: rollback failed (%s); proceeding to close",
251+
"AsyncAdaptedConnection.close (id=%s, peer=%s): "
252+
"rollback failed (%s); proceeding to close",
253+
id(self),
254+
peer,
249255
type(exc).__name__,
250256
exc_info=True,
251257
)

tests/test_aio_close_rollback_log.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ def _fake_await_only(coro: object) -> object:
6767
assert matching[0].exc_info is not None
6868
assert isinstance(matching[0].exc_info[1], OperationalError)
6969
assert fake.close_calls == 1 # close still ran
70+
# Correlation fields: id=<num> and peer=<addr-or-None> so operators
71+
# can attribute the log record to a specific adapter instance / node.
72+
msg = matching[0].getMessage()
73+
assert f"id={id(adapter)}" in msg, msg
74+
assert "peer=" in msg, msg
7075

7176

7277
def test_close_propagates_programming_bug() -> None:

0 commit comments

Comments
 (0)