Windows: deliver error responses + byte-range bodies (issue #82 follow-up)#88
Merged
Conversation
…load (Windows) When the server rejects a request mid-upload (e.g. 413 on an over-limit chunked body), it sent the 4xx then immediately closed the socket. On Windows, closesocket() with unread recv data (the client's in-flight upload) forces an abortive RST that discards the just-sent response, so the client received nothing (empty status). Linux delivered it by luck of softer RST-on-unread timing. Fix: after emit_parse_error sends the 4xx, shutdown(SD_SEND) flushes it + FIN, then the connection enters a lingering-close state — keep reading and DISCARDING the peer's remaining upload until its FIN (EOF -> destroy) or a 5s budget (bounded by the periodic deadline_tick). The final close is then a clean FIN, not an RST. Cross-platform (SHUT_WR on POSIX). Fixes h1/005 on Windows. Full server suite: no regressions (135 pass / 8 fail, all pre-existing; was 133/10).
…sendfile) A byte-range response delivered its body through ZEND_ASYNC_IO_SENDFILE -> uv_fs_sendfile(out = socket). On Windows a TCP socket is a Winsock SOCKET, not a CRT fd, and libuv's win uv_fs_sendfile writes to the out fd via the CRT _write() -- so the body never reaches the socket (206 headers arrive, body empty). Non-range files within the 64 KiB slurp threshold already dodged this via the slurp+writev fast path; ranges were gated out of it. Fix: let the slurp fast path handle ranges too -- read the file (<= 64 KiB) and cut the [first, first+len) slice from the in-memory buffer, sent via the normal writev path. Cross-platform. Fixes static/011-range on Windows. (A range/file larger than the slurp threshold still uses uv_fs_sendfile and remains broken on Windows -- tracked as a follow-up.) Full suite: no regressions (136 pass / 7 fail, all pre-existing).
Contributor
CoverageTotal lines: 81.05% → 79.78% (-1.27 pp)
|
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 distinct Windows response-delivery bugs from the
#82follow-up suite, both confirmed by instrumentation/code analysis. Each is a real correctness fix (Linux passed by luck), and the full serverphptsuite shows no regressions.1. Lingering close — error responses survive close-during-upload (
h1/005)Rejecting a request mid-upload (e.g. 413 on an over-limit chunked body) sent the 4xx and then immediately closed the socket. On Windows,
closesocket()with unread recv data (the client's in-flight upload) forces an abortive RST, which discards the just-sent response — the client saw an empty status. Linux delivered it by luck of softer RST-on-unread timing.Fix: after
emit_parse_errorsends the 4xx,shutdown(SD_SEND)flushes it + FIN, then the connection enters a lingering-close state — keep reading and discarding the peer's remaining upload until its FIN (EOF → destroy) or a 5 s budget (bounded by the periodicdeadline_tick). The final close is then a clean FIN, not an RST. Cross-platform (SHUT_WRon POSIX). Verified: the existingout_in_flight/request_in_flightpaths are guarded so only lingering connections change behaviour.2. Byte-range bodies via read+writev, not sendfile (
static/011-range)A byte-range body was delivered through
ZEND_ASYNC_IO_SENDFILE→uv_fs_sendfile(out = socket). On Windows a TCP socket is a WinsockSOCKET, not a CRT fd, and libuv's winuv_fs_sendfilewrites to the out fd via the CRT — so the body never reached the socket (206 +Content-Rangearrived, body empty). Non-range files ≤ 64 KiB already dodged this via the slurp+writev fast path; ranges were gated out.Fix: let the slurp fast path handle ranges too — read the file (≤ 64 KiB) and cut the
[first, first+len)slice from the in-memory buffer, sent via the normal writev path.Known gap: a range/file larger than the 64 KiB slurp threshold still uses
uv_fs_sendfileand stays broken on Windows — tracked as a follow-up (Windows large-file streaming).Verification (Windows, Debug_TS)
h1/005: PASS ·static/011-range: PASSsendfile): 136 pass / 7 fail / 45 skip — was 133/10 before this branch + the merged test-portability PR. The 7 remaining fails are pre-existing and unrelated (peer-RST cancellation#2, ThreadPool crash#3, precompressed UAF / static-h2#5). No regressions.