Repository navigation
0.3.7 — the read timeout bounds every recv and send, and a request body can be streamed - #29
Merged
Sunrisepeak merged 4 commits intoDec 4, 2026
Conversation
…ody can be streamed (mcpplibs#28) A peer that stopped inside a TLS record held send, send_stream and download_to_file for good: the wait before a read was bounded, the recv mbedtls makes to complete the record was not. A peer that stopped reading held a write the same way. Each recv and send now waits at most readTimeoutMs for progress (Socket::set_idle_timeout, wait_before_send, SO_SNDTIMEO), and write_all bounds the time without progress instead of the whole write. BodySource streams a request body of known length from a reader by offset; BodySource::file reads a file. tests/test_idle_timeout.cpp and tests/test_body_source.cpp cover both.
The 32 MiB upload to a peer that slept 1 ms per record read at about 1 MB/s on Windows, whose timer ticks every 16 ms, and the writer then waited past the 1 s bound for room (Windows CI, both toolchains). An upload whose source is slow and a download whose server is slow move at a pace every system keeps.
This was referenced Dec 4, 2026
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.
Closes #28.
What changes
readTimeoutMsbounds everyrecvandsend. The wait before a read was already bounded. Therecvthat mbedtls makes to complete a TLS record, once the record's first bytes have arrived, was not. A peer that stopped inside a record therefore heldsend,send_streamanddownload_to_fileindefinitely, and a peer that stopped reading held a write the same way.Socket::set_idle_timeout: each wait before arecvorsendof the connection is bounded, andbio_recvandbio_sendwait against that bound. The client sets it toreadTimeoutMsfor every exchange, after the connection is open, so inside anhttps://proxy's tunnel the bottom socket carries it.SO_SNDTIMEOis set to the same value. It covers a send that the poll found room for, but that needs more room than was free.write_allbounds the time without progress, not the whole write. A large body on a slow link is no longer cut while it is still moving.Read timed out before the declared length,No response,Write failed.Streamed request body.
BodySourceholds a size and a function that reads the bytes at a given offset.HttpRequest::bodySourcesends it withContent-Length, in 64 KiB slices, andBodySource::file(path)reads a file. When the request is sent again (a stale pooled connection, or a 307/308 redirect), the source is read again from offset 0. A source that fails ends the request withRequest body source failed at byte N of M, and the server, still owed bytes, has not acted on it. A request that sets bothbodyandbodySourceis refused before anything is sent.The release is a patch release, 0.3.7. Everything is additive. The only change in behaviour is that a stall inside a record now fails after
readTimeoutMsinstead of hanging.Verification
tests/test_idle_timeout.cpp: the peer stops inside a record in the head, in the body, during a stream and during a download; another peer stops reading; a 32 MiB upload keeps moving for longer than the bound. WithreadTimeoutMs = 500, the five stall cases end in about 0.6 s, or 1.2 s for the write. With the idle bound removed (a mutation run), they wait the full 20 s the peer holds the connection.tests/test_body_source.cpp: the bytes the server received are compared for a generated source and for a file; also covered are a source that fails partway, both bodies set at once, and a stale pooled connection that sends the source again from the start.tests/tls_test_server.hpp:Conn::write_cut(a record cut partway),Conn::read_some,Conn::body, and anAfterHandshakehook.mcpp testpasses all 13 programs with gcc 16.1.0 and with llvm 22.1.8 (libc++).Authorship: ai-and-human