Repository navigation
Add timer to hyper server for http2_keepalive_interval - #1726
Merged
Merged
Conversation
djc
added this pull request to the merge queue
Jun 14, 2024
|
@AmeliasCode Thanks to your work. Unfortunately, my test still fails with the fix. Apparently, your test adds let endpoint = Endpoint::from_static("http://localhost:50000")
// commenting out this line turn it into pass.
.http2_keep_alive_interval(std::time::Duration::from_secs(1))
.keep_alive_while_idle(true)
.timeout(std::time::Duration::from_secs(5))
.connect_timeout(std::time::Duration::from_secs(5));Is enabling keepalive at client-side invalid? If so, it should be removed from the API. nit: The commit ordering is very strange. The integration test should have been added at first. |
Contributor
Author
|
@akiradeveloper Sorry for missing that you were experiencing the error on the client side. I was seeing it on the server side so that's what I was focusing on. I have a fix for the client side as well that I'll raise in a moment. |
LucioFranco
added a commit
that referenced
this pull request
Oct 29, 2026
… timeout applies (#2980) ## Motivation Since the hyper 1.0 upgrade, the server's connection builder only gets a timer on its HTTP/2 side (added in #1726 for keepalive). hyper's HTTP/1 `header_read_timeout` defaults to 30s, but hyper silently disables it when no timer is set. As a result, a server built with `accept_http1(true)`, which `tonic-web` requires, never times out a client that doesn't finish sending its request headers. A slowloris client can hold connections open indefinitely and exhaust the server's file descriptors. Users can't fix this from outside, since the connection builder is internal and `Server` exposes no HTTP/1 options. ## Solution Set `TokioTimer` on the HTTP/1 builder too. This only turns on hyper's existing 30s default header read timeout. It adds no new API and changes nothing for HTTP/2-only servers. Adds `http1_header_read_timeout_is_enforced`, which sends a partial HTTP/1 request head, advances the clock past 30s, and checks that the server closed the connection. It fails without the fix and passes with it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
As described in this issue: #1725 the recent upgrade to hyper 1 has broken services that use http2_keepalive_interval. This was due to a missing timer, resulting in panics with the message
You must supply a timer.See here: https://github.com/hyperium/hyper/blob/master/src/common/time.rs#L36Solution
This solution adds in a timer to the server via this method: https://docs.rs/hyper-util/0.1.5/hyper_util/server/conn/auto/struct.Http2Builder.html#method.timer
The timer is a standard tokio timer: https://docs.rs/hyper-util/0.1.5/hyper_util/rt/tokio/struct.TokioTimer.html
Fixes #1725