Repository navigation
fix: skip a live empty WSS frame instead of resubscribing (LAMGTO-59) - #91
palantir-valiot[bot] wants to merge 1 commit into
Conversation
websocket-client.recv() returns "" for a CLOSE frame after marking the socket disconnected, and ""/b"" for a zero-length data frame on a live socket. orjson.loads on that raises JSONDecodeError, which is not a transient socket error, so the router logged ERROR and tore every subscription down. Skip the live frame. A real close still reconnects, at WARNING.
|
The The first error, from
A probe of PR file list ( None of these files is the authors query,
Same file list. Nothing here configures Snyk. |
There was a problem hiding this comment.
Overall Assessment
The PR splits the two meanings of an empty recv() in _sub_routing_loop: a CLOSE frame (connected already False) reconnects at WARNING, and a zero-length data frame on a live socket is skipped at DEBUG instead of raising JSONDecodeError and tearing down every subscription. The discriminator is sound — websocket-client's send_close() sets connected = False before recv() returns the close frame — and the timeout restore was correctly moved ahead of the branch so a stream of empty frames cannot leave the shared socket on the 0.5s poll. No blocking bugs found.
Findings
No actionable findings.
Notes
- Test coverage is good: three new tests pin the split (live empty frame skipped with no
_new_conn, close frame reconnects at WARNING, non-empty malformed JSON still ERROR), and the empty-frame test also asserts the exactsettimeoutsequence so the timeout-restore regression is caught. All three fail against the pre-fix code for the right reason. - Considered but not flagged:
_waiting_connection_ack(GraphQLClient.py:880) still doesorjson.loads(self._conn.recv())with no empty-frame guard. It is the same class of bug on the connect path, but the failure mode is a failed connect (_new_connlogs ERROR and returnsFalse, the router retries with backoff), not a subscription teardown, and the PR scopes the change to_sub_routing_loop. - Considered but not flagged: a persistent stream of empty frames now spins the router at ~200 iterations/s (
poll_interval0.005) and never reconnects. The author explicitly chose to skip live empty frames, and the ping thread still detects a genuinely dead socket, so this is a design trade-off rather than a defect. getattr(self._conn, "connected", True) is Falsetreats a missing attribute as live. websocket-client always setsconnected, so this is defensive only; theis Falsecomparison also avoids treating a falsy non-bool as disconnected.- The
[Dependencies]CHANGELOG line and theuv.lockrefresh are consistent with the lock contents I could read (certifi 2026.11.20,requires-python = ">=3.11"matchingpyproject.toml).
🤖 PR Reviewer · DeepSeek V4.1 Flash (Fireworks)
|
No code change from this review. The empty-frame split, the timeout restore, and the three regression tests are already on
Merge is still blocked for two reasons I cannot clear from this repo:
|
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
3 open issues
What changed in this PR
Fixes false WSS reconnect/resubscribe storms by treating a zero-length recv() on a still-connected socket as a skip (DEBUG) rather than a JSON parsing failure (ERROR), while still reconnecting on real CLOSE frames.
Changes:
- Update
_sub_routing_loopto restore socket timeout and skip live empty frames; log WARNING + reconnect on peer close. - Add regression tests covering empty data frame vs CLOSE frame vs malformed JSON behavior.
- Bump version to 3.10.2 and document the fix in the changelog.
| File | Description |
|---|---|
pygqlc/GraphQLClient.py |
Adjusts subscription routing loop to distinguish live empty frames from CLOSE and avoid unnecessary resubscription. |
tests/pygqlc/gql_client/test_subscribe.py |
Adds targeted tests for empty frame handling, peer close, and malformed JSON behavior. |
tests/pygqlc/gql_client/test_async_client_per_loop.py |
Formatting-only changes (patch calls reflowed). |
pygqlc/__version__.py |
Bumps package version to 3.10.2. |
CHANGELOG.md |
Documents the WSS empty-frame fix and dependency refresh notes. |
Review effort: Lite
| try: | ||
| self._conn.settimeout(0.5) | ||
| raw = self._conn.recv() | ||
| message = orjson.loads(raw) | ||
| # Restore before any branch. The ping thread shares this socket, | ||
| # and a stream of empty frames must not leave it on the 0.5s poll. | ||
| self._conn.settimeout(self.websocket_timeout) |
| except (TimeoutError, websocket.WebSocketTimeoutException): | ||
| time.sleep(self.poll_interval) | ||
| continue |
| assert [c.args[0] for c in gql._conn.settimeout.call_args_list] == [ | ||
| 0.5, | ||
| gql.websocket_timeout, | ||
| 0.5, | ||
| gql.websocket_timeout, | ||
| 0.5, | ||
| gql.websocket_timeout, | ||
| ] |


Summary
A zero-length WSS frame was parsed as JSON, then treated as a dead connection.
lamosa-gto-services-workflowslogged that at ERROR and resubscribed every subscription. The pod stayed healthy. The loss is the false alarm and the dropped subscription window.websocket-client.recv()returns""for two different things. A CLOSE frame, after it has already marked the socket disconnected. And an empty data frame on a socket that is still connected. Both hitorjson.loadsand raiseJSONDecodeError, which is not a transient socket error, so the router logged ERROR and halted.A disconnected socket still reconnects, now at WARNING. A live empty frame is skipped. A non-empty payload that is not JSON still halts at ERROR. I assumed the observed empty document is that
recv()return, not a server sending the JSON value"". If it is a real close,connectedis already false and we still reconnect. The change is inpygqlc/GraphQLClient.pyin_sub_routing_loop.pygqlc#89 (FEMSA-79) is the same split and a reviewer already accepted it, but it never merged. This lands the fix on current main. If #89 merges first, both claim 3.10.2 — close one of them.
Why
LAMGTO-59. Production error in
lamosa-gto-services-workflows(tenant lamosa-gto, prod), podlamosa-gto-services-workflows-77869dff86-pc7rs:Upstream socket churn on the identity websocket is not ours. Classifying that empty recv as a payload bug, and tearing every subscription down for it, is.
Test plan
b""and""on a connected socket called_new_conntwice and would have resubscribed.connected is False, recv returns"") still reconnects, at WARNING, with no ERROR.uv run pyteston the hermetic suite: 100 passed. The integration tests that needAPI/WSS/TOKENwere not run here; they are unchanged.uvx ruff format --checkanduvx bandit -r . -s B101 -llclean.ruff formatalso reflowedtest_async_client_per_loop.py; no behavior change.uv lock --upgrade;uv tree --depth 1 --outdatedreports nothing.Closes LAMGTO-59
💬 Continue the agent chat (live transcript, tools, follow-ups):
https://palantir.valiot.io/agent-tasks?task=37d53c4a-7c19-4c30-8be8-6b55678e2a78