Skip to content

fix(h1): handle every 1xx other than 101 as an interim response - #1737

Merged
FlorentinDUBOIS merged 4 commits into
mainfrom
fix/h1-interim-1xx
Oct 1, 2026
Merged

FlorentinDUBOIS merged 4 commits into
mainfrom
fix/h1-interim-1xx

Conversation

@FlorentinDUBOIS

@FlorentinDUBOIS FlorentinDUBOIS commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

On an HTTP/1.1 frontend, ConnectionH1::writable handled only 100 and 103 from an HTTP/1.1 backend as interim. Any other 1xx (102, or an unassigned 104-199) took the final-response path: the stream was unlinked and the backend returned to the keep-alive pool while its final response was still due.

RFC 9110 §15.2 makes every 1xx interim. The 103 arm now covers 102-199, so the stream stays linked and the final response follows on the same backend connection. 100 and 101 keep their own handling. The access-log tag of an interim response on an unlinked stream becomes H1::Interim.

Tests: test_h1_interim_102_before_final and test_h1_interim_150_before_final (e2e) send an interim then a 200 on a keep-alive backend, then a second exchange on the same connections.

Fixes #1733

Stacked on #1754.

…nfinished request

test_h1_trailer_field_limit_exceeded_split_closes_backend (#1719) checked
that a follow-up request on the same client connection was served after a
400 for an over-bound trailer section. #1726, merged first, closes the H1
client connection when a response completes before its request was
received whole. An over-bound trailer section leaves the request
unfinished: its end cannot be found, so no further request can be read
from that connection (RFC 9112 §6.3). The close is the intended
behaviour, and the follow-up expectation contradicted it, which turned
main red.

The test now checks that, after the 400, the client connection reads EOF
with no further bytes and that a follow-up request reaches no backend.
The other checks are unchanged: head and body forwarded, 400 answered,
backend connection holding the cut request closed.

Since #1726, removing the block of ConnectionH1::readable that ends the
backend stream before the 400 no longer turns this test red: the client
close tears the backend down too. The test doc says so. The 400 arm of
#1719 has no dedicated unit test.

CHANGELOG (#1716 entry), kawa_h1/LIFECYCLE.md §2.3 and the 400-arm
comment in mux/h1.rs said the client connection stays as persistent as
the answer's Connection header; they now say it closes. No runtime
change.

Follow-up to #1719 and #1726.

Signed-off-by: Florentin Dubois <[email protected]>
…er drain test

test_h2_graceful_shutdown_completes_large_transfer slept a fixed 200 ms
after starting its request and then issued soft_stop, assuming the request
had reached the backend. Under load it had not: the worker rightly refused
the not-yet-opened connection or stream, and the test failed with a
connection-level error (connection refused, broken pipe, connection
closed) without ever exercising the in-flight drain it covers.

The backend now holds its response (DelayedH2Backend::start_held), the
test waits until the request has reached it, issues soft_stop, then
releases the 512 KiB response, so the response is still owed when the
soft stop is issued at any load. No production code changed.

Fixes #1736

Signed-off-by: Florentin Dubois <[email protected]>
#1719 made both Position::Server arms of the parse-error branch in
ConnectionH1::readable end the linked backend stream. Only the
cut-response arm had a unit test. The 400 arm relied on the e2e test
test_h1_trailer_field_limit_exceeded_split_closes_backend, which no
longer catches a regression there: since #1726 the client connection
closes after a 400 for an unfinished request, and that close tears the
backend down too.

a_request_error_answered_400_after_linking_ends_the_backend_stream links
a pooled mock H1 backend, reads its complete response without starting
it on the client's wire, then sends a malformed chunk. It asserts that
the stream leaves backend_streams, and that the backend no longer
carries it and is Disconnecting, not pooled.

Seen red with the 400-arm block removed: "the rejected stream must leave
the backend reverse index". Green with it.

CHANGELOG: the #1716 entry names the new test.

Follow-up to #1719.

Signed-off-by: Florentin Dubois <[email protected]>
ConnectionH1::writable kept the stream linked after a 100 or a 103 from
an HTTP/1.1 backend, but sent any other 1xx (102, or an unassigned
104-199) down the final-response path: the stream was unlinked and the
backend returned to the keep-alive pool while its final response was
still due. RFC 9110 section 15.2 makes every 1xx interim; the 103 arm
now covers 102-199. 100 and 101 keep their own handling.

Fixes #1733

Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
FlorentinDUBOIS merged commit a842820 into main Oct 1, 2026
28 checks passed
FlorentinDUBOIS added a commit that referenced this pull request Oct 1, 2026
…riving (#1742)

Fixes #1738

## Problem

When an H1 response completes before its request was received whole, the client connection is closed as soon as the response is flushed (#1721). The close is immediate. A socket closed with request bytes still unread, or one that receives more after the close, makes the kernel send a reset that discards the part of the response that is still queued.

## Fix

RFC 9112 §9.6 staged close, in `ConnectionH1` (`lib/src/protocol/mux/h1.rs`), whenever the close follows a response while part of the request has arrived but not all of it. This includes the answers sozu generates itself (400, 401, 413, 503, 504). A request of which no byte arrived, such as the 408 to a silent client, closes at once as before:

- The backend stream is ended right away, which disconnects the backend (#1721).
- Once the response and any TLS `close_notify` are flushed, `shutdown(SHUT_WR)`: the FIN follows the response.
- What the client still sends is read from the raw socket into a 16 KiB stack buffer and dropped. No allocation, nothing parsed or forwarded.
- The connection closes on the client's EOF, on a socket error, after 4 MiB (`LINGER_MAX_BYTES`), or at the listener's `request_timeout` counted from the end of the response, whichever comes first. `ConnectionH1::arm_timeout` is a no-op while lingering, so no caller moves the deadline, including the re-arm after `Mux::timeout_inner`'s write pass. Drained bytes count as frontend bytes in. `Mux::timeout_inner` closes a lingering frontend before any per-stream timeout handling.
- A frontend HUP while lingering reads to the EOF before closing, rather than closing with bytes unread.
- A soft stop lets a lingering session run until its own deadline.

There is no new setting. The time bound reuses `request_timeout`.

Docs: `lib/src/protocol/mux/LIFECYCLE.md` §8.4, `doc/configure.md` (`request_timeout`, `http.close.request_incomplete`), and the `CHANGELOG.md` Unreleased / Fixed section.

## Tests

- e2e `test_h1_early_response_survives_the_rest_of_the_upload`: the client keeps uploading while it reads a large early 413. The last body byte is withheld, so the request never completes. With the fix reverted, the test fails 3 runs out of 3: the client receives only part of the response body and then a reset. With the fix it passes.
- unit `a_lingering_close_half_closes_then_drains_to_the_client_eof`: checks the FIN, the drained byte count, that the deadline does not move, and the close on EOF.
- unit `a_lingering_close_stops_at_its_byte_budget_and_its_deadline`.
- unit `a_linger_started_by_a_timeout_write_keeps_its_own_deadline` and `a_408_to_a_silent_client_closes_without_lingering`. Both fail without the second commit: the deadline was 60 s instead of 5 s, and the 408 returned `Continue` instead of `CloseSession`.
- unit `a_silent_client_is_closed_at_the_linger_deadline`.
- Each unit test fails under the mutation named in its doc comment.
- `a_deferred_tls_close_completes_the_response_once`: once `close_notify` is flushed the connection now lingers (`Continue`) instead of returning `CloseSession`. The test also asserts the FIN and the `CloseSession` that follows the client's EOF.
- `a_fin_after_epoll_wait_closes_the_backend_on_the_next_round_at_the_latest`: the fixture used to stage a request that was never parsed, i.e. an incomplete one, and that path now ends the backend stream at once. It now stages what the test is about: a complete request whose client asked to close. Assertions are unchanged.
- `try_h1_early_response_mid_upload` closes its client before the soft stop, so the stop does not wait for the linger deadline.



Stacked on #1737.



Signed-off-by: Florentin Dubois <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(h1): only 100 and 103 are handled as interim responses on an H1 frontend

1 participant