Skip to content

mux: a close-delimited response keeps the H1 client connection open after the body #1642

Closed

Description

@FlorentinDUBOIS

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_delimited ends the BodySize::Empty body with an end_stream flag and ParsingPhase::Terminated.
  • HttpContext::on_response_headers (lib/src/protocol/kawa_h1/editor.rs) only clears keep_alive_backend on a backend Connection: close. It does not elide the header, which reaches the client, and nothing clears keep_alive_frontend, which only follows the client's request.
  • ConnectionH1::writable, frontend position, once the terminated response is flushed: the if stream.context.keep_alive_frontend branch re-arms the timeout, resets the stream to Idle and waits for the next request. Nothing distinguishes a response whose framing requires the connection to close.

Scenario

  1. A keep-alive HTTP/1.1 client sends GET /api HTTP/1.1.
  2. 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.
  3. 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.
  4. 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-Encoding or Content-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: close must 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: Connection is hop-by-hop. If sozu keeps the client connection, it should not forward the backend's Connection: close either.

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.

Refs: #1633, #1640.

Activity

  1. added a commit that references this issue on Sep 28, 2026
    21f9ff9
  2. added a commit that references this issue on Sep 28, 2026
    eadfa4a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions