Skip to content

Mux: response truncated to a slow client when the backend closed with data still buffered #1819

Closed

Description

@FlorentinDUBOIS

Summary

Sōzu can truncate a response to a slow client when the backend has already sent the whole response and closed its connection. The client gets part of the body and then a clean close. Nothing is logged at the default level. The only trace is the http.infinite_loop.error counter.

Seen as an intermittent failure of tls_tests::test_plain_client_half_close_after_request_receives_large_response (CI run 37019159928: 8,284,694 of 8,388,608 body bytes, then a FIN). Locally it only fails when the client is starved of CPU. An instrumented backend read the whole request, wrote all 8 MiB, and closed cleanly.

Mechanism

In Mux::ready_inner (lib/src/protocol/mux/mod.rs):

  1. The backend's FIN has arrived, so its readiness carries HUP. Its stream buffer is full because the client reads slowly, so the dead-backend check keeps the connection (has_buffer_pressure). Bytes still wait in its kernel socket.
  2. The backend's interest includes HUP | ERROR, so its filter_interest() stays HUP and is never empty. That keeps all_backends_readiness_are_empty false. The inner loop never breaks: the frontend would block and the backend is parked, so no pass can make progress, and the loop spins to MAX_LOOP_ITERATIONS (10 000) inside a single ready() call.
  3. At the limit, the code checks only the connection-level frontend.has_pending_write(), which ignores the data still queued in the stream's buffer. It returns SessionResult::Close without logging, and the end of the body is never sent.

The client's half-close plays no part: a slow client downloading any response larger than the buffers, from a backend that closes right after answering, can hit this. The fault is in the readiness loop, so HTTP/1.1 and HTTP/2 frontends are both exposed.

A unit test that drives Mux::ready with an H1 frontend whose socket would block, and a backend that wrote 160 KiB and closed, fails on main on every run: the first pass returns Close. Readiness at the limit: frontend I(RWEH-) R(-----), backend I(R-EH-) R(---H-) under buffer pressure, frontend.has_pending_write() == false, one block still in back.out. The client received 32,805 of 163,883 bytes.

This is a different defect from the truncation fixed in #1640 (a backend FIN in the middle of the body forwarded as a complete response). Here the backend sends a complete response and the proxy drops its tail.

Expected

  • A dead backend kept only for its buffered bytes is not counted as work for the loop.
  • The loop-limit branch never drops queued stream data. It waits for the next writable event instead, and logs a warning when it fires.
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