Ignore unsolicited and duplicate Pong frames - #1122
Conversation
The WebSocket protocol permits a peer to send an unsolicited Pong, and a peer may also duplicate a Pong for an outstanding Ping. In both cases the payload has no matching entry in the ping manager, and `ack()` raised a `KeyError` that escaped the receive loop. Pop the ping event with a default and only set it when present, so stray Pong frames are ignored instead of terminating the receive worker.
|
Docs preview: https://d8fc7c5b-httpx2-docs.pydantic.workers.dev |
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 06d086bbaf
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
The WebSocket protocol permits a peer to send an unsolicited
Pong, and a peer may also duplicate aPongfor an outstandingPing. In both cases the payload has no matching entry in the ping manager, soack()raised aKeyErrorthat escaped the receive loop and stopped the background receive worker (the sync thread died silently; the async task tore down the session's task group).PingManager.ack()andAsyncPingManager.ack()now pop the ping event with a default and only set it when present, so strayPongframes are ignored. Added regression tests toTestReceivePingcovering both the sync and async loops.AI Disclaimer
This PR was developed with the assistance of either Claude or Codex. I've reviewed and verified the changes.