Skip to content

Avoid encoding errors in PING and PONG frame logging - #1766

Closed
GruffElixir wants to merge 1 commit into
python-websockets:mainfrom
GruffElixir:fix/1763-control-frame-logging
Closed

GruffElixir wants to merge 1 commit into
python-websockets:mainfrom
GruffElixir:fix/1763-control-frame-logging

Conversation

@GruffElixir

Copy link
Copy Markdown

Summary

Escape non-ASCII text when rendering PING and PONG payloads for log messages. These control frames can contain internally generated random bytes; if they happen to decode as Unicode, writing the log message through a non-UTF-8 handler can raise UnicodeEncodeError. ASCII payloads and other frame representations retain their existing output.

Test plan

  • PYTHONPATH=src python -m unittest tests.test_frames tests.test_protocol tests.test_connection
  • python -m ruff format --check src/websockets/frames.py tests/test_frames.py
  • python -m ruff check src/websockets/frames.py tests/test_frames.py
  • git diff --check

Fixes #1763

Copilot AI lite review requested due to automatic review settings September 15, 2026 22:18

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@aaugustin

Copy link
Copy Markdown
Member

IMO that would be a bug in the handler. It's the responsibility of the handler to decide how to deal with data that it cannot encode.

@aaugustin aaugustin closed this Sep 17, 2026
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.

Ping/pong frame logging can produce text that crashes non-UTF-8 log handlers (UnicodeEncodeError)

3 participants