From ef9ebaacdda254c9b3c85d36a47b09a502ac1a45 Mon Sep 17 00:00:00 2001 From: June Kim Date: Sat, 9 May 2026 10:12:28 -0700 Subject: [PATCH] feat(http2/client): expose reset_stream_duration option Expose the h2 client builder's reset_stream_duration setting, which controls how long reset stream state is kept in memory. This is useful for tuning memory usage in connections that reset many streams. Closes #2599 (partial) --- src/client/conn/http2.rs | 30 ++++++++++++++++++++++++++++++ src/proto/h2/client.rs | 5 +++++ 2 files changed, 35 insertions(+) diff --git a/src/client/conn/http2.rs b/src/client/conn/http2.rs index d62b4a4e99..f1bc4b1ecc 100644 --- a/src/client/conn/http2.rs +++ b/src/client/conn/http2.rs @@ -503,6 +503,36 @@ where self } + /// Sets the duration to remember locally reset streams. + /// + /// When a stream is explicitly reset by either the client or the server, + /// the HTTP/2 specification requires that any further frames received for + /// that stream must be ignored for "some time". + /// + /// In order to satisfy the specification, internal state must be maintained + /// to implement the behavior. This state grows linearly with the number of + /// streams that are locally reset. + /// + /// The `reset_stream_duration` setting configures the max amount of time + /// this state will be maintained in memory. Once the duration elapses, the + /// stream state is purged from memory. + /// + /// Once the stream has been fully purged from memory, any additional frames + /// received for that stream will result in a connection level protocol + /// error, forcing the connection to terminate. + /// + /// The default value is determined by the `h2` crate, and is currently + /// 1 second. + /// + /// See the documentation of [`h2::client::Builder::reset_stream_duration`] for more + /// details. + /// + /// [`h2::client::Builder::reset_stream_duration`]: https://docs.rs/h2/client/struct.Builder.html#method.reset_stream_duration + pub fn reset_stream_duration(&mut self, dur: Duration) -> &mut Self { + self.h2_builder.reset_stream_duration = Some(dur); + self + } + /// Constructs a connection with the configured options and IO. /// See [`client::conn`](crate::client::conn) for more. /// diff --git a/src/proto/h2/client.rs b/src/proto/h2/client.rs index bf154e4580..51f548444e 100644 --- a/src/proto/h2/client.rs +++ b/src/proto/h2/client.rs @@ -77,6 +77,7 @@ pub(crate) struct Config { pub(crate) max_local_error_reset_streams: Option, pub(crate) header_table_size: Option, pub(crate) max_concurrent_streams: Option, + pub(crate) reset_stream_duration: Option, } impl Default for Config { @@ -97,6 +98,7 @@ impl Default for Config { max_local_error_reset_streams: Some(1024), header_table_size: None, max_concurrent_streams: None, + reset_stream_duration: None, } } } @@ -126,6 +128,9 @@ fn new_builder(config: &Config) -> Builder { if let Some(max) = config.max_concurrent_streams { builder.max_concurrent_streams(max); } + if let Some(dur) = config.reset_stream_duration { + builder.reset_stream_duration(dur); + } builder }