Skip to content

fix: assemble bulk streambuf reads across short recv#24

Merged
ruoka merged 1 commit into
masterfrom
cursor/critical-bug-management-d95a
Jul 19, 2026
Merged

fix: assemble bulk streambuf reads across short recv#24
ruoka merged 1 commit into
masterfrom
cursor/critical-bug-management-d95a

Conversation

@cursor

@cursor cursor Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Bug and impact

endpointbuf::xsgetn returned after the first successful recv when the remaining read was ≥ the TCP buffer size (4096). istream::read then set failbit on 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_size could fail with io_error and 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 recv as a complete xsgetn result. That is unsafe for istream::read, which expects xsgetn to keep gathering until the requested count, EOF, or a hard error.

Fix

Loop recv in the large-read path until the request is satisfied (or EOF/EINTR/EWOULDBLOCK/hard error), mirroring send_all on the write side.

Validation

  • Added regression: split write so the server must assemble across short recvs
  • Added WebSocket echo of a payload > tcp_buffer_size
  • NET_DISABLE_NETWORK_TESTS=0 ./tools/CB.sh debug test — new tests passed (unrelated flaky posix/socket env assertions remain)
Open in Web View Automation 

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>
@ruoka ruoka self-assigned this Jul 19, 2026
@ruoka ruoka added the bug label Jul 19, 2026
@ruoka
ruoka marked this pull request as ready for review July 19, 2026 14:02
@cursor

cursor Bot commented Jul 19, 2026

Copy link
Copy Markdown
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.

@ruoka
ruoka merged commit 2754f2e into master Jul 19, 2026
4 checks passed
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
ruoka deleted the cursor/critical-bug-management-d95a branch July 20, 2026 00:42
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants