Skip to content

fix(h1): end the connection after a failed or short file body (#362) - #363

Merged
EdmondDantes merged 10 commits into
mainfrom
fix/h1-short-file-body
Sep 30, 2026
Merged

EdmondDantes merged 10 commits into
mainfrom
fix/h1-short-file-body

Conversation

@EdmondDantes

@EdmondDantes EdmondDantes commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Closes #362.

An HTTP/1 file body that failed or came up short left the connection open, so the next response was read as the rest of the body.

  • Both HTTP/1 on_done callbacks honour the engine's status; a failed body marks the framing lost, so http_request_finalize neither keeps the connection nor serves a pipelined request.
  • Plaintext sendfile reports bytes_sent < body_length as a failure (php-async completes a sendfile at EOF with status 0 and a short count).
  • A body sized from a stale open-file cache entry evicts it, so the next request is sized from the file.
  • The engine takes its defer timer before arming the caller; a refusal returns SEND_FILE_REFUSED and the request is answered whole (static: the synchronous path; sendFile(): 500) instead of completing inside the HTTP/1 parser.
  • --enable-fault-injection compiles libfiu fault points and _http_fault_* hooks; the Linux debug CI leg enables it.

Needs true-async/php-async#308 (merged as 1521d69): Windows TransmitFile now reports a short transfer, and Darwin/FreeBSD wait out EAGAIN instead of cutting a 2 MiB body at about 1 MB.

Evidence: h1/065 (stale cache, plaintext) red 5 of 5 on main with the pipelined 200 glued after 4096 of 2097152 bytes, h1/068 the same over TLS, h1/066 and h1/067 through fault points red 3 of 3; all green on Linux, macOS and Windows CI. Local suite 520 of 546 passed, 25 skipped; the one failure is core/018's known log-ring overflow under -j4 (plan item 13), passing alone.

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

@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Total lines: 83.70% → 83.83% (+0.14 pp)

File Baseline Current Δ Touched
src/core/fault_hooks.c 0.00% 100.00% +100.00 pp ●
src/core/http_connection.c 83.64% 83.82% +0.18 pp ●
src/core/http_connection.h 81.82% 81.82% +0.00 pp ●
src/core/http_connection_tls.c 76.01% 76.26% +0.25 pp
src/core/tls_layer.c 77.17% 77.69% +0.52 pp
src/http1/http1_sendfile.c 73.20% 77.78% +4.58 pp ●
src/http3/http3_listener.c 76.61% 76.76% +0.15 pp
src/http_send_file.c 82.47% 82.47% +0.00 pp ●
src/http_server.c 95.20% 95.24% +0.04 pp ●
src/http_server_class.c 75.99% 75.95% -0.04 pp
src/http_server_config.c 92.58% 92.52% -0.06 pp
src/send_file.c 87.17% 87.50% +0.33 pp ●
src/static/http_static.c 89.12% 89.12% +0.00 pp ●
src/static/http_static_cache.c 69.82% 80.68% +10.86 pp ●
src/websocket/ws_session.c 89.71% 89.89% +0.18 pp

@EdmondDantes
EdmondDantes marked this pull request as ready for review September 30, 2026 17:36
@EdmondDantes
EdmondDantes merged commit 0ec0fed into main Sep 30, 2026
8 checks passed
@EdmondDantes
EdmondDantes deleted the fix/h1-short-file-body branch September 30, 2026 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTTP/1: a failed or short file body keeps the connection alive

1 participant