Skip to content

Commit bbd9dee

Browse files
committed
feat(http2): add config for max_local_error_reset_streams in server
This change exposes a tunable for the max_local_error_reset_streams parameter in h2.
1 parent 98a7ab0 commit bbd9dee

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ http = "0.2"
2828
http-body = "0.4"
2929
httpdate = "1.0"
3030
httparse = "1.8"
31-
h2 = { version = "0.3.17", optional = true }
31+
h2 = { version = "0.3.24", optional = true }
3232
itoa = "1"
3333
tracing = { version = "0.1", default-features = false, features = ["std"] }
3434
pin-project-lite = "0.2.4"

src/proto/h2/server.rs

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const DEFAULT_STREAM_WINDOW: u32 = 1024 * 1024; // 1mb
3939
const DEFAULT_MAX_FRAME_SIZE: u32 = 1024 * 16; // 16kb
4040
const DEFAULT_MAX_SEND_BUF_SIZE: usize = 1024 * 400; // 400kb
4141
const DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE: u32 = 16 << 20; // 16 MB "sane default" taken from golang http2
42+
const DEFAULT_MAX_LOCAL_ERROR_RESET_STREAMS: usize = 1024;
4243

4344
#[derive(Clone, Debug)]
4445
pub(crate) struct Config {
@@ -49,6 +50,7 @@ pub(crate) struct Config {
4950
pub(crate) enable_connect_protocol: bool,
5051
pub(crate) max_concurrent_streams: Option<u32>,
5152
pub(crate) max_pending_accept_reset_streams: Option<usize>,
53+
pub(crate) max_local_error_reset_streams: Option<usize>,
5254
#[cfg(feature = "runtime")]
5355
pub(crate) keep_alive_interval: Option<Duration>,
5456
#[cfg(feature = "runtime")]
@@ -67,6 +69,7 @@ impl Default for Config {
6769
enable_connect_protocol: false,
6870
max_concurrent_streams: None,
6971
max_pending_accept_reset_streams: None,
72+
max_local_error_reset_streams: Some(DEFAULT_MAX_LOCAL_ERROR_RESET_STREAMS),
7073
#[cfg(feature = "runtime")]
7174
keep_alive_interval: None,
7275
#[cfg(feature = "runtime")]
@@ -125,6 +128,7 @@ where
125128
.initial_connection_window_size(config.initial_conn_window_size)
126129
.max_frame_size(config.max_frame_size)
127130
.max_header_list_size(config.max_header_list_size)
131+
.max_local_error_reset_streams(config.max_local_error_reset_streams)
128132
.max_send_buffer_size(config.max_send_buffer_size);
129133
if let Some(max) = config.max_concurrent_streams {
130134
builder.max_concurrent_streams(max);

src/server/conn.rs

+17
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,23 @@ impl<E> Http<E> {
414414
self
415415
}
416416

417+
/// Configures the maximum number of pending reset streams allowed before a GOAWAY will be sent.
418+
///
419+
/// This will default to the default value set by the [`h2` crate](https://crates.io/crates/h2).
420+
/// As of v0.3.17, it is 20.
421+
///
422+
/// See <https://github.com/hyperium/hyper/issues/2877> for more information.
423+
#[cfg(feature = "http2")]
424+
#[cfg_attr(docsrs, doc(cfg(feature = "http2")))]
425+
pub fn http2_max_local_error_reset_streams(
426+
&mut self,
427+
max: impl Into<Option<usize>>,
428+
) -> &mut Self {
429+
self.h2_builder.max_local_error_reset_streams = max.into();
430+
431+
self
432+
}
433+
417434
/// Sets the [`SETTINGS_INITIAL_WINDOW_SIZE`][spec] option for HTTP2
418435
/// stream-level flow control.
419436
///

src/server/server.rs

+15
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,21 @@ impl<I, E> Builder<I, E> {
387387
self
388388
}
389389

390+
/// Configures the maximum number of local reset streams allowed before a GOAWAY will be sent.
391+
///
392+
/// If not set, hyper will use a default, currently of 1024.
393+
///
394+
/// If `None` is supplied, hyper will not apply any limit.
395+
/// This is not advised, as it can potentially expose servers to DOS vulnerabilities.
396+
///
397+
/// See <https://rustsec.org/advisories/RUSTSEC-2024-0003.html> for more information.
398+
#[cfg(feature = "http2")]
399+
#[cfg_attr(docsrs, doc(cfg(feature = "http2")))]
400+
pub fn http2_max_local_error_reset_streams(mut self, max: impl Into<Option<usize>>) -> Self {
401+
self.protocol.http2_max_local_error_reset_streams(max);
402+
self
403+
}
404+
390405
/// Sets the [`SETTINGS_INITIAL_WINDOW_SIZE`][spec] option for HTTP2
391406
/// stream-level flow control.
392407
///

0 commit comments

Comments
 (0)