Repository navigation
sendfile: report the bytes TransmitFile sent, and wait out EAGAIN on Darwin and FreeBSD - #308
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…eBSD, instead of failing the transfer
…e count off the file pointer
EdmondDantes
added a commit
to true-async/server
that referenced
this pull request
Sep 30, 2026
…363) A failed or short HTTP/1 file body kept the connection alive, so the next response was read as the rest of the body. The on_done callbacks honour the engine status and mark the framing lost, plaintext sendfile reports a short count as a failure, a stale cache entry is evicted, and a refused deferred start is answered whole. Adds --enable-fault-injection (libfiu) with _http_fault_* hooks. Needs true-async/php-async#308. Mutants: S2, hand 10 by 28.2: 9 killed, 1 survived (fault_hooks.c name-length bound, now killed by core/083), 0 not run; base eaa2d57
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.
Two defects in the sendfile backend, both found through true-async/server#362 (a file body cut short must end the HTTP/1 connection).
Windows: TransmitFile counted the bytes it was asked for.
io_transmitfile_work_cbadded the requested chunk totransferredafter each call. TransmitFile stops at EOF and still succeeds, so a file truncated after its size was taken reported the full length. The worker now reads each pass's count off the file pointer TransmitFile advanced and stops at the first short pass.Darwin and FreeBSD: EAGAIN failed the transfer. libuv calls sendfile(2) on the non-blocking socket there and returns -1/EAGAIN when a full socket buffer took nothing (
src/unix/fs.c);io_sendfile_zc_cbcompleted that as an error. On macOS CI (server PR #363) a 2 MiB plaintext body reached the client cut at 1,129,404 bytes (debug) and 998,696 (release). Linux never gets EAGAIN here: libuv falls back to a copy loop that polls. The request now waits for the socket to become writable (uv_poll on anF_DUPFD_CLOEXECdup, since the stream handle holds the descriptor in the poller) and submits the rest. A dispose during the wait, and a close of the destination io, end the wait with UV_ECANCELED, so the dup never outlives the connection.Evidence: the wait path, forced on Linux by a temporary hack that turned every other positive sendfile result into EAGAIN, served 176 of 176 server phpt over sendfile, static, h1, h2 and tls. The php-async suite passes locally except the six tests whose
../../../../includes miss through a symlinked ext/async, as on main. The macOS and Windows proof is the server CI against this branch (true-async/server#363).