fix: assemble bulk streambuf reads across short recv#24
Merged
Conversation
endpointbuf::xsgetn returned after the first successful recv when the remaining request was >= the buffer size. istream::read then set failbit on a short TCP segment even though more bytes were still in flight, breaking WebSocket payloads and other large reads. Loop recv until the request is satisfied (or EOF/error), and add regression coverage with a split write and a large WebSocket echo. Co-authored-by: Kaius Ruokonen <ruoka@users.noreply.github.com>
Contributor
Author
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
1 task
ruoka
added a commit
that referenced
this pull request
Jul 19, 2026
The TCP short-recv loop from PR #24 also ran for SOCK_DGRAM. Because udp_buffer_size equals the bulk-read threshold, istream::read of a max-sized buffer blocked after the first datagram and could merge messages. Gate assemble-on-short-recv to stream sockets only. Co-authored-by: Kaius Ruokonen <ruoka@users.noreply.github.com>
ruoka
added a commit
that referenced
this pull request
Jul 19, 2026
The TCP short-recv loop from PR #24 also ran for SOCK_DGRAM. Because udp_buffer_size equals the bulk-read threshold, istream::read of a max-sized buffer blocked after the first datagram and could merge messages. Gate assemble-on-short-recv to stream sockets only. Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Kaius Ruokonen <ruoka@users.noreply.github.com>
ruoka
added a commit
that referenced
this pull request
Jul 21, 2026
fix: assemble bulk streambuf reads across short recv
ruoka
added a commit
that referenced
this pull request
Jul 21, 2026
The TCP short-recv loop from PR #24 also ran for SOCK_DGRAM. Because udp_buffer_size equals the bulk-read threshold, istream::read of a max-sized buffer blocked after the first datagram and could merge messages. Gate assemble-on-short-recv to stream sockets only. Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Kaius Ruokonen <ruoka@users.noreply.github.com>
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.
Bug and impact
endpointbuf::xsgetnreturned after the first successfulrecvwhen the remaining read was ≥ the TCP buffer size (4096).istream::readthen setfailbiton a short TCP segment even though more bytes were still in flight.Impact: WebSocket text frames (and any other bulk
istream::read) larger than one segment/tcp_buffer_sizecould fail withio_errorand drop the session — silent user-facing breakage for payloads the API claims to support (up to 1 MiB).Root cause
The bulk-read fast path treated a partial
recvas a completexsgetnresult. That is unsafe foristream::read, which expectsxsgetnto keep gathering until the requested count, EOF, or a hard error.Fix
Loop
recvin the large-read path until the request is satisfied (or EOF/EINTR/EWOULDBLOCK/hard error), mirroringsend_allon the write side.Validation
recvstcp_buffer_sizeNET_DISABLE_NETWORK_TESTS=0 ./tools/CB.sh debug test— new tests passed (unrelated flaky posix/socket env assertions remain)