Skip to content

Commit 2d1bd70

Browse files
magurotunaseanmonstar
authored andcommittedFeb 28, 2024·
fix(http2): initial_max_send_streams defaults to 100
1 parent e77c839 commit 2d1bd70

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed
 

‎src/client/conn/http2.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,15 @@ where
310310
/// This value will be overwritten by the value included in the initial
311311
/// SETTINGS frame received from the peer as part of a [connection preface].
312312
///
313-
/// The default value is determined by the `h2` crate, but may change.
313+
/// Passing `None` will do nothing.
314+
///
315+
/// If not set, hyper will use a default.
314316
///
315317
/// [connection preface]: https://httpwg.org/specs/rfc9113.html#preface
316318
pub fn initial_max_send_streams(&mut self, initial: impl Into<Option<usize>>) -> &mut Self {
317-
self.h2_builder.initial_max_send_streams = initial.into();
319+
if let Some(initial) = initial.into() {
320+
self.h2_builder.initial_max_send_streams = initial;
321+
}
318322
self
319323
}
320324

‎src/proto/h2/client.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,21 @@ const DEFAULT_STREAM_WINDOW: u32 = 1024 * 1024 * 2; // 2mb
5252
const DEFAULT_MAX_FRAME_SIZE: u32 = 1024 * 16; // 16kb
5353
const DEFAULT_MAX_SEND_BUF_SIZE: usize = 1024 * 1024; // 1mb
5454

55+
// The maximum number of concurrent streams that the client is allowed to open
56+
// before it receives the initial SETTINGS frame from the server.
57+
// This default value is derived from what the HTTP/2 spec recommends as the
58+
// minimum value that endpoints advertise to their peers. It means that using
59+
// this value will minimize the chance of the failure where the local endpoint
60+
// attempts to open too many streams and gets rejected by the remote peer with
61+
// the `REFUSED_STREAM` error.
62+
const DEFAULT_INITIAL_MAX_SEND_STREAMS: usize = 100;
63+
5564
#[derive(Clone, Debug)]
5665
pub(crate) struct Config {
5766
pub(crate) adaptive_window: bool,
5867
pub(crate) initial_conn_window_size: u32,
5968
pub(crate) initial_stream_window_size: u32,
60-
pub(crate) initial_max_send_streams: Option<usize>,
69+
pub(crate) initial_max_send_streams: usize,
6170
pub(crate) max_frame_size: u32,
6271
pub(crate) keep_alive_interval: Option<Duration>,
6372
pub(crate) keep_alive_timeout: Duration,
@@ -72,7 +81,7 @@ impl Default for Config {
7281
adaptive_window: false,
7382
initial_conn_window_size: DEFAULT_CONN_WINDOW,
7483
initial_stream_window_size: DEFAULT_STREAM_WINDOW,
75-
initial_max_send_streams: None,
84+
initial_max_send_streams: DEFAULT_INITIAL_MAX_SEND_STREAMS,
7685
max_frame_size: DEFAULT_MAX_FRAME_SIZE,
7786
keep_alive_interval: None,
7887
keep_alive_timeout: Duration::from_secs(20),
@@ -86,14 +95,12 @@ impl Default for Config {
8695
fn new_builder(config: &Config) -> Builder {
8796
let mut builder = Builder::default();
8897
builder
98+
.initial_max_send_streams(config.initial_max_send_streams)
8999
.initial_window_size(config.initial_stream_window_size)
90100
.initial_connection_window_size(config.initial_conn_window_size)
91101
.max_frame_size(config.max_frame_size)
92102
.max_send_buffer_size(config.max_send_buffer_size)
93103
.enable_push(false);
94-
if let Some(initial_max_send_streams) = config.initial_max_send_streams {
95-
builder.initial_max_send_streams(initial_max_send_streams);
96-
}
97104
if let Some(max) = config.max_concurrent_reset_streams {
98105
builder.max_concurrent_reset_streams(max);
99106
}

0 commit comments

Comments
 (0)
Please sign in to comment.