Repository navigation
Description
Summary
When an H1 backend answers with a close-delimited body (no Content-Length, no chunked coding; RFC 9112 §6.3 rule 8) and closes, sozu forwards the response to a keep-alive H1 client, including the backend's Connection: close header, and then keeps the client connection open. Such a body can only end with the close, so the client keeps waiting for more body bytes until sozu's frontend timeout closes the connection. Any response sozu writes on that connection afterwards is appended to the close-delimited body from the client's point of view.
Observed on origin/main (6eef0ba1) by reading. Reproduced end to end on the #1640 branch (bc35e2eb), which does not change this path: the client reads HTTP/1.1 200 OK\r\nConnection: close\r\nSozu-Id: …\r\n\r\nabcd and the connection is still open 4 s after the backend closed.
Mechanism
ConnectionH1::readable(lib/src/protocol/mux/h1.rs), backend position, on the backend EOF:ConnectionH1::terminate_close_delimitedends theBodySize::Emptybody with anend_streamflag andParsingPhase::Terminated.HttpContext::on_response_headers(lib/src/protocol/kawa_h1/editor.rs) only clearskeep_alive_backendon a backendConnection: close. It does not elide the header, which reaches the client, and nothing clearskeep_alive_frontend, which only follows the client's request.ConnectionH1::writable, frontend position, once the terminated response is flushed: theif stream.context.keep_alive_frontendbranch re-arms the timeout, resets the stream toIdleand waits for the next request. Nothing distinguishes a response whose framing requires the connection to close.
Scenario
- A keep-alive HTTP/1.1 client sends
GET /api HTTP/1.1. - The backend answers
HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n<body>and closes. HTTP/1.0 or legacy backends often do this. - The client receives the head and the body, but no close. By RFC 9112 §6.3 rule 8 it must read until the close, so the request looks stalled until the frontend timeout.
- Pipelining: a client that sent a second request before reading this response gets that second response appended to the first body. An intermediary that pools connections to sozu can then attribute bytes of one response to another request.
References
- RFC 9112 §6.3 rule 8: without
Transfer-EncodingorContent-Length, the response body length is determined by the number of octets received before the server closes the connection. - RFC 9112 §9.6: a server that sends
Connection: closemust initiate a close of the connection after that response, and must not process further requests on it. A proxy forwarding a close-delimited response to an HTTP/1.1 client has two conforming choices: close the client connection after the body, or re-frame the body with chunked coding and keep the connection. - RFC 9110 §7.6.1:
Connectionis hop-by-hop. If sozu keeps the client connection, it should not forward the backend'sConnection: closeeither.
Expected
For an H1 frontend, a response whose body is delimited by the backend close (BodySize::Empty in the body phase) ends the client connection: clear keep_alive_frontend, or close through the same defer_close_for_tls_flush (write-only shutdown) path #1640 uses for an incomplete response, once the body is flushed. Alternatively, re-frame it as chunked for HTTP/1.1 clients. A test: keep-alive client, backend Connection: close + close-delimited body + close; the client must reach EOF right after the body, and no pipelined response may follow it.
Activity
fix(mux): close an H1 client connection after the backend's Connectio…
fix(mux): close an H1 client connection after the backend's Connectio…