Repository navigation
fix: treat dead-socket OSError as a transient WSS reconnect (FEMSA-80) - #90
Conversation
A peer close makes websocket-client reply with a close frame on an already-dead socket. That raises OSError(EBADF), which missed TRANSIENT_WS_ERRORS and was logged as ERROR with a traceback. Classify EBADF, ENOTCONN, and a bare ECONNRESET as a calm reconnect on both recv and ping. Other OSErrors still log at ERROR.
There was a problem hiding this comment.
Overall Assessment
The PR adds _is_transient_ws_error, which classifies a bare OSError with EBADF, ENOTCONN, or ECONNRESET as a transient WSS teardown, and uses it in both _sub_routing_loop and _ping_pong. Reconnect behavior is unchanged; only the log level moves from ERROR to WARNING for those errnos. The implementation is small, matches the existing TRANSIENT_WS_ERRORS pattern, and the tests cover the positive cases plus an EACCES negative control. No blocking bugs found.
Findings
No actionable findings.
Notes
- Test coverage is good:
EBADF/ENOTCONNare parametrized on the recv path,EACCESproves the change does not blanket-catchOSError, and the ping path has its ownEBADFcase. All tests are hermetic (mock socket, no sleeps). _is_transient_ws_erroris a module-level helper rather than a method, which fits the existing module-levelTRANSIENT_WS_ERRORSconstant. It is not exported, so no public API change.- Considered but not flagged:
_is_transient_ws_erroris not applied to theexcept BrokenPipeErrorin_unsubscribe. That path already logs at WARNING and is outside this PR's scope;BrokenPipeErroris already inTRANSIENT_WS_ERRORSanyway. - Considered but not flagged:
OSErrorwitherrno=None(e.g.OSError("msg")) falls through to ERROR. That is the intended conservative behavior per the PR description. - The CHANGELOG entry and version bump to 3.10.1 follow the repo's release convention.
🤖 PR Reviewer · DeepSeek V4.1 Flash (Fireworks)
|
No code changes from this review. The findings section has nothing to act on, and there are no inline threads. Merge stays blocked on the CI that this change can affect is green: That is an org quota, not a finding in this diff, and it is not a required check on the |
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
2 open issues
What changed in this PR
Reduces error-level log noise during WSS subscription teardown by treating specific dead-socket OSError errnos as transient reconnect conditions (FEMSA-80).
Changes:
- Add
_is_transient_ws_error()to classifyEBADF/ENOTCONN/ bareECONNRESETas transient WSS errors. - Downgrade logging from ERROR to WARNING for these transient teardown cases in
_sub_routing_loopand_ping_pong. - Add regression tests and bump version + changelog for 3.10.1.
| File | Description |
|---|---|
pygqlc/GraphQLClient.py |
Adds transient OSError classification helper and uses it to adjust WSS teardown logging behavior. |
tests/pygqlc/gql_client/test_subscribe.py |
Adds tests asserting WARNING vs ERROR logging for dead-socket and non-dead-socket OSError cases. |
pygqlc/__version__.py |
Bumps library version to 3.10.1. |
CHANGELOG.md |
Documents the behavior change and release notes for 3.10.1. |
Review effort: Lite
| from . import subscriptions as subs | ||
| from . import mutations as muts | ||
| import errno | ||
| import types | ||
| import time |
| they must be classified as a transient teardown — WARNING and reconnect, | ||
| not ERROR with a traceback. ECONNRESET is already ConnectionResetError.""" | ||
| gql = routing_client | ||
| gql._conn.recv.side_effect = OSError(errno_code, "Bad file descriptor") |

Summary
A normal peer close of a WSS subscription was logged as ERROR with a full traceback. The socket still reconnects. The damage is log noise that can hide a real WSS failure.
websocket-clientanswers that close with a close frame on the already-dead socket.sock.sendthen raisesOSError: [Errno 9] Bad file descriptor. Python does not promoteEBADForENOTCONNto aConnection*subclass, so the error missedTRANSIENT_WS_ERRORSand took the ERROR branch in_sub_routing_loop.Why
FEMSA-80, seen once on
femsa-worker-monitorsin femsa prod. No user-visible loss:wss_conn_haltedwas already set and the loop reconnects with backoff.I did not add all of
OSErrortoTRANSIENT_WS_ERRORS. That would also swallowPermissionErrorand other real bugs. A helper treatsEBADF,ENOTCONN, and a bareECONNRESETas transient. Every otherOSErrorstill logs at ERROR.OSError(ECONNRESET)is already aConnectionResetErrorwhen Python constructs it; the errno covers a bareOSErrorwhose errno was copied or assigned later. The ping send path uses the same helper, since it shares the classification.Reconnect behavior is unchanged. Only the log level moves from ERROR to WARNING for these errnos. Version 3.10.1.
Test plan
OSError(EBADF)andOSError(ENOTCONN)fromrecvlogged ERROR before the fix, WARNING after.OSError(EACCES)still logs ERROR, so the change does not blanket-catchOSError.OSError(EBADF)logs WARNING and setswss_conn_halted.uv run pytest: 97 passed. The 25 live tests that needAPI/WSS/TOKENerror locally without those secrets. That is pre-existing; CI injects the secrets.uvx ruff format --checkuvx bandit -r . -s B101 -llcleanuv lock --upgrade;uv tree --depth 1 --outdatedreports nothingScreenshots not applicable. This is a library change with no UI.
Closes FEMSA-80
💬 Continue the agent chat (live transcript, tools, follow-ups):
https://palantir.valiot.io/agent-tasks?task=b74c4655-8469-4a2c-ada7-dbfccd912693