Skip to content

reassemble twisted websocket messages before passing them to the listener - #52

Merged
bentsku merged 1 commit into
mainfrom
websocket-message-reassembly
Oct 7, 2026
Merged

bentsku merged 1 commit into
mainfrom
websocket-message-reassembly

Conversation

@bentsku

@bentsku bentsku commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

wsproto emits the data of a message as it arrives: one event per frame of a fragmented message (RFC 6455 section 5.4), and several events for a single frame that is bigger than one socket read. WebSocketChannel queued each of these events as is, so a twisted listener received a partial message from every receive(). For example, a 64 KiB text message sent as one frame arrived as two messages, and a message sent as four 32 KiB frames as six. The ASGI path is not affected, since the ASGI servers reassemble messages before passing them on.

Changes

  • WebSocketChannel.dataReceived buffers the data of a text or binary message until wsproto reports message_finished, and queues one event with the whole message. Control frames sent in the middle of a fragmented message (e.g. pings) are still handled as before.

Testing

  • New test_receive_large_message (twisted and asgi): the client sends a 1 MiB text and a 1 MiB binary message, each as a single frame. The listener must receive each as one message.
  • New test_receive_fragmented_message (twisted and asgi): the client sends a text message as three frames with a ping in between, then a binary message as two frames. The listener must receive two complete messages.
  • Both twisted variants fail without the change. The full suite passes (192 tests) and lint is clean.

🤖 Generated with Claude Code

…ener

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bentsku
bentsku added this pull request to stack #54 October 7, 2026 00:54
@bentsku bentsku changed the title websocket message reassembly reassemble twisted websocket messages before passing them to the listener Oct 7, 2026
@bentsku
bentsku marked this pull request as ready for review October 7, 2026 09:43
@bentsku
bentsku merged commit b05d49a into main Oct 7, 2026
5 checks passed
@bentsku
bentsku deleted the websocket-message-reassembly branch October 7, 2026 10:24
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