WebSocket client: respect write capacity during upgrade - #1678
Open
meganetaaan wants to merge 1 commit into
Open
WebSocket client: respect write capacity during upgrade#1678meganetaaan wants to merge 1 commit into
meganetaaan wants to merge 1 commit into
Conversation
13 tasks
meganetaaan
marked this pull request as ready for review
August 15, 2026 16:15
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.
Summary
Make
embedded:network/websocket/clientrespect the socket's reported writable capacity while sending the HTTP Upgrade request.The client currently records
onWritable(count), but sends the complete Upgrade request in a singlewrite(). A TLS socket may initially expose less writable capacity than the request, especially when custom headers make the handshake larger. In that case the connection fails before the Upgrade request reaches the server.Root cause
The
"connecting"branch builds the HTTP Upgrade request and immediately passes the entireArrayBufferto the socket. Unlike WebSocket frame writes after the connection is established, this path does not compare the request size with#writable.On an ESP32-S3, a deliberately enlarged 12,370-byte Upgrade request received writable capacities of 5,648, 2,771, 2,771, and 1,180 bytes. The existing implementation attempted the full 12,370-byte write and failed before opening the WebSocket. With this change, the same request was sent in four writes and the WSS connection opened successfully.
Changes
sendRequeststate that writes at most the currently reported capacity.receiveStatusonly after the complete Upgrade request has been sent.Validation
\r\n\r\nis sent.