Skip to content

Commit

Permalink
fix(http2): initial_max_send_streams defaults to 100
Browse files Browse the repository at this point in the history
  • Loading branch information
magurotuna authored and seanmonstar committed Feb 28, 2024
1 parent e77c839 commit 2d1bd70
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/client/conn/http2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,15 @@ where
/// This value will be overwritten by the value included in the initial
/// SETTINGS frame received from the peer as part of a [connection preface].
///
/// The default value is determined by the `h2` crate, but may change.
/// Passing `None` will do nothing.
///
/// If not set, hyper will use a default.
///
/// [connection preface]: https://httpwg.org/specs/rfc9113.html#preface
pub fn initial_max_send_streams(&mut self, initial: impl Into<Option<usize>>) -> &mut Self {
self.h2_builder.initial_max_send_streams = initial.into();
if let Some(initial) = initial.into() {
self.h2_builder.initial_max_send_streams = initial;
}
self
}

Expand Down
17 changes: 12 additions & 5 deletions src/proto/h2/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,21 @@ const DEFAULT_STREAM_WINDOW: u32 = 1024 * 1024 * 2; // 2mb
const DEFAULT_MAX_FRAME_SIZE: u32 = 1024 * 16; // 16kb
const DEFAULT_MAX_SEND_BUF_SIZE: usize = 1024 * 1024; // 1mb

// The maximum number of concurrent streams that the client is allowed to open
// before it receives the initial SETTINGS frame from the server.
// This default value is derived from what the HTTP/2 spec recommends as the
// minimum value that endpoints advertise to their peers. It means that using
// this value will minimize the chance of the failure where the local endpoint
// attempts to open too many streams and gets rejected by the remote peer with
// the `REFUSED_STREAM` error.
const DEFAULT_INITIAL_MAX_SEND_STREAMS: usize = 100;

#[derive(Clone, Debug)]
pub(crate) struct Config {
pub(crate) adaptive_window: bool,
pub(crate) initial_conn_window_size: u32,
pub(crate) initial_stream_window_size: u32,
pub(crate) initial_max_send_streams: Option<usize>,
pub(crate) initial_max_send_streams: usize,
pub(crate) max_frame_size: u32,
pub(crate) keep_alive_interval: Option<Duration>,
pub(crate) keep_alive_timeout: Duration,
Expand All @@ -72,7 +81,7 @@ impl Default for Config {
adaptive_window: false,
initial_conn_window_size: DEFAULT_CONN_WINDOW,
initial_stream_window_size: DEFAULT_STREAM_WINDOW,
initial_max_send_streams: None,
initial_max_send_streams: DEFAULT_INITIAL_MAX_SEND_STREAMS,
max_frame_size: DEFAULT_MAX_FRAME_SIZE,
keep_alive_interval: None,
keep_alive_timeout: Duration::from_secs(20),
Expand All @@ -86,14 +95,12 @@ impl Default for Config {
fn new_builder(config: &Config) -> Builder {
let mut builder = Builder::default();
builder
.initial_max_send_streams(config.initial_max_send_streams)
.initial_window_size(config.initial_stream_window_size)
.initial_connection_window_size(config.initial_conn_window_size)
.max_frame_size(config.max_frame_size)
.max_send_buffer_size(config.max_send_buffer_size)
.enable_push(false);
if let Some(initial_max_send_streams) = config.initial_max_send_streams {
builder.initial_max_send_streams(initial_max_send_streams);
}
if let Some(max) = config.max_concurrent_reset_streams {
builder.max_concurrent_reset_streams(max);
}
Expand Down

0 comments on commit 2d1bd70

Please sign in to comment.