Repository navigation
Description
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):
- 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. - The backend's interest includes
HUP | ERROR, so itsfilter_interest()staysHUPand is never empty. That keepsall_backends_readiness_are_emptyfalse. The inner loop never breaks: the frontend would block and the backend is parked, so no pass can make progress, and the loop spins toMAX_LOOP_ITERATIONS(10 000) inside a singleready()call. - 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 returnsSessionResult::Closewithout 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.
Activity
fix(mux): keep a HUP sozu raises mid-pass as loop work, bound the lim…
fix(mux): count loop-limit progress from a session-wide client byte c…
fix(mux): stop truncating a slow client's response when its backend c…