Skip to content

Commit 0db4361

Browse files
Align _socket_looks_dead docstring with implementation
The function returns True when _protocol is missing or None, but the old docstring claimed missing attributes default to False ("assume alive"). The implementation is the right contract — a connection without a protocol cannot pass any peer-FIN peek, so treating it as dead avoids handing zombie connections out — but the docstring was backwards and would have led future maintainers to debug a non-existent bug. Rewrite to enumerate the four positive dead-signals (no protocol, !is_wire_coherent, transport.is_closing, reader.at_eof) and clarify that mock-tolerance applies only to the transport peek arms. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent d82041b commit 0db4361

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

src/dqliteclient/pool.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,27 @@
6767
def _socket_looks_dead(conn: DqliteConnection) -> bool:
6868
"""Best-effort local detection of a half-closed TCP socket.
6969
70-
Returns True only on an affirmative bool signal from the transport or
71-
reader. Mocked / missing attributes default to False (assume alive) so
72-
the check never produces a false positive against well-behaved peers.
70+
Returns True if any of:
71+
72+
* ``_protocol`` is missing or None — the connection was never
73+
handshaked, or has been invalidated; we cannot peek a transport,
74+
so we treat as dead so the caller drops it.
75+
* ``_protocol.is_wire_coherent`` is False — wire desync from a
76+
prior parse failure; the next round-trip is wasted RTT.
77+
* ``transport.is_closing()`` is True — peer FIN already observed.
78+
* ``reader.at_eof()`` is True — same shape, observed via reader.
79+
80+
Returns False otherwise. Mocked / partially-built objects whose
81+
transport peek attributes (``transport``, ``reader``) are missing
82+
or raise ``AttributeError`` / ``RuntimeError`` are treated as
83+
alive for those individual peeks — the function only flags an
84+
affirmative dead signal from the transport / reader paths.
85+
86+
The "missing ``_protocol`` is dead" branch is intentional: a real
87+
connection always has the attribute (possibly None for never-
88+
connected / invalidated state); the only way to reach this branch
89+
in production is a connection that genuinely has no usable
90+
protocol.
7391
"""
7492
# ``getattr`` (rather than direct attribute access) so the function
7593
# tolerates partial mocks that omit ``_protocol`` entirely — the

0 commit comments

Comments
 (0)