You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Pipelined HTTP/1 responses come back out of order when a large one follows a small one #209
Three pipelined requests on one plaintext HTTP/1 connection come back in the
order 1, 3, 2. A pipelined client matches responses to requests by order
(RFC 9112 §9.3.1), so it reads response 3's body as the answer to request 2 and
response 2's as the answer to request 3.
Reproduction
Handler answers /1 and /2 with a 2-byte body and /3 with 1800 bytes. All
three requests are written in one fwrite, so they land in the read buffer
together.
GET /1 HTTP/1.1 … GET /2 HTTP/1.1 … GET /3 HTTP/1.1 (Connection: close)
Bodies read back off the socket, three runs out of three:
order: S1,L3,S2
Cause
The HTTP/1 dispose picks its sender by body size
(src/core/http_connection.c:2965):
under HTTP_WRITEV_THRESHOLD (1024) — http_connection_send_zstr_batched,
which honours the connection's write ordering: one uv_write in flight at a
time, everything behind it appended to conn->out_pending_buf, drained by the
completion callback;
at or over it — http_connection_send_strv_owned, which submits ZEND_ASYNC_IO_WRITEV straight at conn->io (:1946) without reading out_in_flight and without setting it.
So response 1 goes in flight, response 2 is appended to the pending tail, and
response 3 is submitted directly past both. libuv writes it as soon as
response 1 completes; the tail carrying response 2 follows.
http_connection_send_str_owned (:1888) has the same shape and is used by the
HTTP/1 sendfile head (src/http1/http1_sendfile.c:213).
Scope
Plaintext HTTP/1 only. TLS goes through tls_push and the BIO ring. HTTP/2 and
HTTP/3 frame and order their own streams.
http_connection_emit_parse_error also bypasses the tail — a direct send(2) in
the plaintext read callback (:2140) — but it retires the connection in the same
breath and its bypass is documented with a reason. Named here, not part of this.
What to do
Bring the two owned-buffer senders under the same discipline as the batched ones:
append behind an in-flight write, and mark the connection in flight when they
submit. http_connection_send_batched_writev already does exactly this for an
iov with a free callback.
Evidence to write
A phpt pipelining small, small, large on one connection and asserting the bodies
come back in request order.
The parse-error responder is not the safe exception the report assumed. Same three pipelined requests with the last one malformed answer 200, 400, 200, three runs out of three: the 4xx is built in the read path and, in a coroutine context, went out through http_connection_send → http_connection_send_raw, which submits at the io like the owned senders did.
Fixed in the same branch: the plaintext side queues through http_connection_send_batched in both contexts, and the destroy that follows already defers on out_in_flight, so the response still leaves before the connection goes. TLS keeps the two paths it had — the awaited send through the BIO pair in a coroutine, the read FSM's atomic SSL_write outside one.
Evidence: h1/051, which reads 200, 400, 200 against main.
Also checked and not filed: http_connection_send_raw reads neither out_in_flight nor the tail either, and no reproduction puts it out of order. An HTTP/1 connection dispatches one request at a time and the await drains the tail before the next handler starts.
Activity
fix(http1): queue the parse-error response behind the writes ahead of…
EdmondDantes commentedon Aug 21, 2026
The parse-error responder is not the safe exception the report assumed. Same three pipelined requests with the last one malformed answer
200, 400, 200, three runs out of three: the 4xx is built in the read path and, in a coroutine context, went out throughhttp_connection_send→http_connection_send_raw, which submits at the io like the owned senders did.Fixed in the same branch: the plaintext side queues through
http_connection_send_batchedin both contexts, and the destroy that follows already defers onout_in_flight, so the response still leaves before the connection goes. TLS keeps the two paths it had — the awaited send through the BIO pair in a coroutine, the read FSM's atomic SSL_write outside one.Evidence:
h1/051, which reads200, 400, 200againstmain.Also checked and not filed:
http_connection_send_rawreads neitherout_in_flightnor the tail either, and no reproduction puts it out of order. An HTTP/1 connection dispatches one request at a time and the await drains the tail before the next handler starts.Merge pull request #210 from true-async/209-pipelined-response-order
chore(core): drop the MSG_NOSIGNAL shim left without a call site by #209