Repository navigation
fix(server): start h1 header read timeout when conn is idle, a de facto idle timeout - #3828
Conversation
|
For the record (even if just for future me), merging this allows a potential future addition of an |
- ext: add ext::on_informational() callback extension (<hyperium/hyper#3818>) (<hyperium/hyper@8ce1fcf>, closes <hyperium/hyper#2565>) - server: add http1::Builder::ignore_invalid_headers(bool) option (<hyperium/hyper#3824>) (<hyperium/hyper@3817a79>) - server: - start http1 header read timeout when conn is idle (<hyperium/hyper#3828>) (<hyperium/hyper@10b09ff>, closes <hyperium/hyper#3780>, <hyperium/hyper#3781>) - change max_local_error_reset_streams function to &mut self (#3820) (e981a91e) - http2::Builder::max_local_error_reset_streams() now takes &mut self and returns &mut Self. In practice, this shouldn't break almost anyone. It was the wrong receiver and return types. (<hyperium/hyper@e981a91>) Co-authored-by: Sean McArthur <sean@seanmonstar.com> Co-authored-by: Finn Bear <finnbearlabs@gmail.com> Co-authored-by: tottoto <tottotodev@gmail.com>
…1 connections With --enable-http2, SGLang serves through Granian and passes no HTTP/1.1 settings. Granian has no HTTP/1.1 keep-alive timeout of its own. Since hyper 1.6 (hyperium/hyper#3828), the HTTP/1.1 header read timeout is re-armed whenever a keep-alive connection goes idle, so Granian's 30 s default closes every idle connection after 30 s. SGLANG_TIMEOUT_KEEP_ALIVE has no effect, because only uvicorn reads it. Clients that pool connections for longer than 30 s can reuse a connection just as the server closes it, and the request fails (aiohttp: "Can not write request body", ServerDisconnectedError or ECONNRESET). Pass HTTP1Settings(header_read_timeout=max(Granian default, SGLANG_TIMEOUT_KEEP_ALIVE * 1000)) to both the embedded and the multi-process Granian server. The timeout never drops below Granian's default, so the 5 s env default, and any value up to 30 s, changes nothing. Larger values now take effect under --enable-http2, as they already do under uvicorn. Under Granian the same timeout also bounds how long a client may take to send request headers, so a larger value relaxes that bound too. The HTTP/2 settings and the other server arguments are unchanged. Add a CPU unit test for the mapping (including unparsable values) and the wiring, and document the Granian behaviour in the environment variable reference. Building HTTP1Settings in _run_granian_server follows the approach of sgl-project#29560. Signed-off-by: Rohan Varma <rohanv@nvidia.com>
I've run into a new issue: if header_read_timeout is set to a relatively short value, hyper ends up incorrectly affecting other long-lived connections. Do you have any plans to implement this improvement? |
As a user of
|
Using hyper as the server and Jetty as the client:
|
|
Thanks! The one thing I don't understand is that you said you can't modify the header read timeout. Setting it to If you have no control over hyper's timeouts, that presents a problem, even if idle timeout was added (which I support). If hyper chooses a default idle timeout of anything other than Another workaround you could try: send a keepalive HTTP GET request if no other requests were sent in the last 25 seconds. This would reset the server's timeout, while helping to detect a connection failure that could have happened for a variety of reasons. |
|
Thank you for your reply. |
|
Please review #4293 to confirm it fixes your issue :) |
Motivation
Currently, the header read timeout is started before any part of the first request is received. This allows closing the connection if no requests are received. However, after the first request, the connection can remain open indefinitely. This change ensures that the header read timeout is started immediately after the connection is idle, following the transmission of the response, before the first part of the subsequent request is received.
This is particularly relevant in the case that browsers open 6+ h1 connections when a page loads and then neglect to close any of them, distracting, in my case, from DDoS attackers.
This is kind of like an "idle timeout"
Changes
header_read_timeoutwhen waiting for subsequent requestsError::is_timeoutreturns true onHeaderTimeoutTests
header_read_timeout_slow_writesheader_read_timeout_slow_writes_multiple_requestsOpen question
Should the documentation of
header_read_timeoutchange? It currently doesn't say when the timeout is started, only when it finishes (client transmits entire header).Related
Related: #1628
Related/Fixes: #2355
Related #3185 (comment)
Builds on and supersedes/Closes #3781 (credit to @T-aian)
Fixes #3780
Supersedes #3743 (this PR required additional complexity, but allowed a different value for the header read timeout and the idle timeout)