Description
Policy question: should a TCP pipe keep the response half open after a client half-close?
When a TCP client sends its request and then calls shutdown(SHUT_WR), Sōzu closes the session as soon as the request bytes have been flushed to the backend. The backend's response never reaches the client, even though the client's read side is still open.
Where it happens
Pipe::check_connections (lib/src/protocol/pipe.rs) decides whether a pipe stays open:
(ConnectionStatus::Closed, ConnectionStatus::Normal) => request_is_inflight,
(ConnectionStatus::WriteOpen, ConnectionStatus::Normal) => request_is_inflight || response_is_inflight,Pipe::frontend_hup marks the frontend Closed on EPOLLRDHUP, even though a read-half close leaves the response direction usable (WRITE_CLOSED is not set). After the last request byte is written, request_is_inflight becomes false and the pipe closes before the backend answers. The Normal/WriteOpen arms carry an explicit comment explaining why this is the current policy: it avoids keeping HTTP-over-TCP Connection: close sessions with no Content-Length open.
Measurement
On a plain TCP listener with no PROXY protocol, a client that half-closes after its request received the backend response in 0 of 40 runs. This applies to every TCP session, not only expect-proxy ones. test_tcp_proxy_half_close (e2e/src/tests/tcp_tests.rs) deliberately makes no promise about it ("TCP proxies may or may not forward data after client half-close").
The question
- Keep the current behaviour: close once the request is flushed. A half-closing TCP client starts over on a new connection. This fits the general preference that a TCP session should rather start over cleanly than linger.
- Keep the response half open while the backend still answers, as HAProxy does: propagate the FIN to the backend (
shutdown(SHUT_WR)) and close only after the backend closes or a timeout fires. This would needPipe::frontend_hupto tell a read-half close (EPOLLRDHUP) apart from a hang-up (EPOLLHUP/WRITE_CLOSED), plus a matchingcheck_connectionsarm and a timeout bound.
Context: this came up in #1823 and #1836. #1836 fixes the PROXY-v2 header being dropped when its bytes and the FIN arrive together, but the response after the half-close is still not delivered because of this policy.
Activity
docs(proxy-protocol): state the health-check logging change and softe…
fix(proxy-protocol): drain a PROXY-v2 header coalesced with the clien…
fix(proxy-protocol): preserve payload after short v2 headers (#1844)
FlorentinDUBOIS commentedon Oct 5, 2026
Decided: when a client half-closes a TCP pipe, Sōzu drains the request bytes already buffered toward the backend, closes the old session, and the client reconnects on a fresh connection. Keeping the response direction open after a client half-close is not planned. The drain behaviour is covered by the TCP/UDP lifecycle boundary tests merged in #1849 (0f28147), which also closed #1823.