Skip to content

fix(http1): queue an owned-buffer response behind the write in flight (#209) - #210

Merged
EdmondDantes merged 3 commits into
mainfrom
209-pipelined-response-order
Aug 21, 2026
Merged

EdmondDantes merged 3 commits into
mainfrom
209-pipelined-response-order

Conversation

@EdmondDantes

Copy link
Copy Markdown
Contributor

Closes #209. Carries the plan correction that PR 208 held, now that writing the
reproduction turned its open item into a defect.

Three pipelined requests on one plaintext HTTP/1 connection, answered with 2, 2
and 1800 bytes, came back in the order 1, 3, 2 — three runs out of three. A
pipelined client matches responses to requests by order (RFC 9112 §9.3.1), so it
read response 3's body as the answer to request 2.

Cause

The dispose picks its sender by body size. Under HTTP_WRITEV_THRESHOLD it uses
http_connection_send_zstr_batched, which honours the connection's write
ordering: one write in flight, everything behind it in conn->out_pending_buf,
drained by the completion callback. At or over the threshold it used
http_connection_send_strv_owned, which submitted ZEND_ASYNC_IO_WRITEV
straight at conn->io — reading neither out_in_flight nor setting it.

So response 1 went in flight, response 2 into the tail, and response 3 past both.

Fix

Both owned-buffer senders now submit through http_connection_send_batched_writev,
which already implements that discipline for an iov with a free callback. The
slots travel as its user data and are released once, wherever the write ends.
http_connection_send_str_owned becomes the one-slot case, and the callback that
released a single body is gone with it.

http_connection_emit_parse_error still bypasses the tail with a direct send(2)
and stays that way: it retires the connection in the same breath, and the bypass
is documented against a race with the close. Named in the issue, not changed.

What the plan correction says

The two remaining HTTP/1 outbound steps rested on "that number has never been
taken". It was taken on 2026-08-20 and is in dev/BENCHMARKS.md, the change it
supported has landed, and it explicitly does not support the queue design. #179 is
left with one thing to argue on its own: a non-blocking tryWrite() on HTTP/1.

Evidence

h1/049 pipelines small, small, large on one connection and reads the bodies
back. Against main:

- order: S1,S2,L3      + order: S1,L3,S2

Local run: 459 phpt, 434 passed, 0 failed, 24 skipped on absent tool gates, 1 warn
(core/047, the pre-existing XFAIL that passes). ctest 16 of 16.

@github-actions

github-actions Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Total lines: 82.62% → 82.54% (-0.07 pp)

File Baseline Current Δ Touched
src/core/http_connection.c 75.87% 77.53% +1.66 pp ●
src/http2/http2_session.c 88.76% 85.61% -3.16 pp
src/http3/http3_callbacks.c 82.42% 83.39% +0.96 pp
src/http3/http3_io.c 89.09% 89.45% +0.36 pp
src/http3/http3_listener.c 77.03% 77.93% +0.90 pp
src/http_body_stream.c 84.85% 75.76% -9.09 pp
src/http_request.c 84.05% 80.96% -3.09 pp
src/websocket/ws_session.c 90.59% 90.04% -0.55 pp

@EdmondDantes
EdmondDantes merged commit 919dab4 into main Aug 21, 2026
8 checks passed
@EdmondDantes
EdmondDantes deleted the 209-pipelined-response-order branch August 21, 2026 20:43
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.

Pipelined HTTP/1 responses come back out of order when a large one follows a small one

1 participant