Skip to content

Ignore unsolicited and duplicate Pong frames - #1122

Merged
Kludex merged 1 commit into
mainfrom
handle-unsolicited-pong
Aug 7, 2026
Merged

Ignore unsolicited and duplicate Pong frames#1122
Kludex merged 1 commit into
mainfrom
handle-unsolicited-pong

Conversation

@Kludex

@Kludex Kludex commented Aug 7, 2026

Copy link
Copy Markdown
Member

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, so ack() raised a KeyError that 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() and AsyncPingManager.ack() now pop the ping event with a default and only set it when present, so stray Pong frames are ignored. Added regression tests to TestReceivePing covering 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.

Review in cubic

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.
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

@codspeed-hq

codspeed-hq Bot commented Aug 7, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 16 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing handle-unsolicited-pong (06d086b) with main (cbfc0e0)

Open in CodSpeed

Footnotes

  1. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/httpx2/httpx2/websockets/_ping.py
@Kludex
Kludex merged commit 454b8b2 into main Aug 7, 2026
18 checks passed
@Kludex
Kludex deleted the handle-unsolicited-pong branch August 7, 2026 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant