Skip to content

Commit d7680e3

Browse files
authoredJan 19, 2024
feat(http2): add config for max_local_error_reset_streams in server (#3530)
This change exposes a tunable for the max_local_error_reset_streams parameter in h2.
1 parent fdfa60d commit d7680e3

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed
 

‎Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ tokio = { version = "1", features = ["sync"] }
3030

3131
futures-channel = { version = "0.3", optional = true }
3232
futures-util = { version = "0.3", default-features = false, optional = true }
33-
h2 = { version = "0.4", optional = true }
33+
h2 = { version = "0.4.2", optional = true }
3434
http-body-util = { version = "0.1", optional = true }
3535
httparse = { version = "1.8", optional = true }
3636
httpdate = { version = "1.0", optional = true }

‎src/proto/h2/server.rs

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const DEFAULT_MAX_FRAME_SIZE: u32 = 1024 * 16; // 16kb
4141
const DEFAULT_MAX_SEND_BUF_SIZE: usize = 1024 * 400; // 400kb
4242
// 16 MB "sane default" taken from golang http2
4343
const DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE: u32 = 16 << 20;
44+
const DEFAULT_MAX_LOCAL_ERROR_RESET_STREAMS: usize = 1024;
4445

4546
#[derive(Clone, Debug)]
4647
pub(crate) struct Config {
@@ -51,6 +52,7 @@ pub(crate) struct Config {
5152
pub(crate) enable_connect_protocol: bool,
5253
pub(crate) max_concurrent_streams: Option<u32>,
5354
pub(crate) max_pending_accept_reset_streams: Option<usize>,
55+
pub(crate) max_local_error_reset_streams: Option<usize>,
5456
pub(crate) keep_alive_interval: Option<Duration>,
5557
pub(crate) keep_alive_timeout: Duration,
5658
pub(crate) max_send_buffer_size: usize,
@@ -67,6 +69,7 @@ impl Default for Config {
6769
enable_connect_protocol: false,
6870
max_concurrent_streams: Some(200),
6971
max_pending_accept_reset_streams: None,
72+
max_local_error_reset_streams: Some(DEFAULT_MAX_LOCAL_ERROR_RESET_STREAMS),
7073
keep_alive_interval: None,
7174
keep_alive_timeout: Duration::from_secs(20),
7275
max_send_buffer_size: DEFAULT_MAX_SEND_BUF_SIZE,
@@ -130,6 +133,7 @@ where
130133
.initial_connection_window_size(config.initial_conn_window_size)
131134
.max_frame_size(config.max_frame_size)
132135
.max_header_list_size(config.max_header_list_size)
136+
.max_local_error_reset_streams(config.max_pending_accept_reset_streams)
133137
.max_send_buffer_size(config.max_send_buffer_size);
134138
if let Some(max) = config.max_concurrent_streams {
135139
builder.max_concurrent_streams(max);

‎src/server/conn/http2.rs

+15
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,21 @@ impl<E> Builder<E> {
132132
self
133133
}
134134

135+
/// Configures the maximum number of local reset streams allowed before a GOAWAY will be sent.
136+
///
137+
/// If not set, hyper will use a default, currently of 1024.
138+
///
139+
/// If `None` is supplied, hyper will not apply any limit.
140+
/// This is not advised, as it can potentially expose servers to DOS vulnerabilities.
141+
///
142+
/// See <https://rustsec.org/advisories/RUSTSEC-2024-0003.html> for more information.
143+
#[cfg(feature = "http2")]
144+
#[cfg_attr(docsrs, doc(cfg(feature = "http2")))]
145+
pub fn max_local_error_reset_streams(mut self, max: impl Into<Option<usize>>) -> Self {
146+
self.h2_builder.max_local_error_reset_streams = max.into();
147+
self
148+
}
149+
135150
/// Sets the [`SETTINGS_INITIAL_WINDOW_SIZE`][spec] option for HTTP2
136151
/// stream-level flow control.
137152
///

0 commit comments

Comments
 (0)
Please sign in to comment.