Repository navigation
reassemble twisted websocket messages before passing them to the listener - #52
Merged
Merged
Conversation
…ener Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bentsku
added this pull request to stack #54
October 7, 2026 00:54
bentsku
marked this pull request as ready for review
October 7, 2026 09:43
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
WebSocketChannelqueued each of these events as is, so a twisted listener received a partial message from everyreceive(). 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.dataReceivedbuffers the data of a text or binary message until wsproto reportsmessage_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
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.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.🤖 Generated with Claude Code