Skip to content

Commit 3722892

Browse files
committed
feat(volo-grpc): expose http2_max_pending_accept_reset_streams on Server
hyper/h2 already supports capping the number of remotely-reset streams pending acceptance before closing the connection, but volo-grpc's gRPC server didn't expose it. Under load, servers hit hyper's default limit (20) and log repeated "remotely-reset pending-accept streams reached limit" warnings with no way to raise it. Adds Server::http2_max_pending_accept_reset_streams, following the same Http2Config passthrough pattern as the other http2_* setters (http2_max_concurrent_streams, http2_max_header_list_size, etc). Default is unchanged (None, i.e. hyper's own default). Closes #657
1 parent 43dd124 commit 3722892

1 file changed

Lines changed: 36 additions & 1 deletion

File tree

volo-grpc/src/server/mod.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,16 @@ impl<IL, OL, SP> Server<IL, OL, SP> {
179179
self
180180
}
181181

182+
/// Sets the max number of remotely-reset streams pending acceptance
183+
/// across the lifetime of the connection.
184+
///
185+
/// If the remote peer exceeds this limit, the connection will be
186+
/// closed. If not set, will default from underlying transport.
187+
pub fn http2_max_pending_accept_reset_streams(mut self, max: impl Into<Option<usize>>) -> Self {
188+
self.http2_config.max_pending_accept_reset_streams = max.into();
189+
self
190+
}
191+
182192
/// Allow this server to accept http1 requests.
183193
///
184194
/// Accepting http1 requests is only useful when developing `grpc-web`
@@ -418,7 +428,10 @@ impl<IL, OL, SP> Server<IL, OL, SP> {
418428
.keep_alive_timeout(self.http2_config.http2_keepalive_timeout)
419429
.max_frame_size(self.http2_config.max_frame_size)
420430
.max_send_buf_size(self.http2_config.max_send_buf_size)
421-
.max_header_list_size(self.http2_config.max_header_list_size);
431+
.max_header_list_size(self.http2_config.max_header_list_size)
432+
.max_pending_accept_reset_streams(
433+
self.http2_config.max_pending_accept_reset_streams,
434+
);
422435

423436
let mut watch = rx.clone();
424437
spawn(async move {
@@ -510,6 +523,7 @@ pub struct Http2Config {
510523
pub(crate) max_frame_size: Option<u32>,
511524
pub(crate) max_send_buf_size: usize,
512525
pub(crate) max_header_list_size: u32,
526+
pub(crate) max_pending_accept_reset_streams: Option<usize>,
513527
pub(crate) accept_http1: bool,
514528
}
515529

@@ -525,7 +539,28 @@ impl Default for Http2Config {
525539
max_frame_size: None,
526540
max_send_buf_size: DEFAULT_MAX_SEND_BUF_SIZE,
527541
max_header_list_size: DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE,
542+
max_pending_accept_reset_streams: None,
528543
accept_http1: false,
529544
}
530545
}
531546
}
547+
548+
#[cfg(test)]
549+
mod tests {
550+
use super::*;
551+
552+
#[test]
553+
fn http2_max_pending_accept_reset_streams_defaults_to_none() {
554+
let server = Server::new();
555+
assert_eq!(server.http2_config.max_pending_accept_reset_streams, None);
556+
}
557+
558+
#[test]
559+
fn http2_max_pending_accept_reset_streams_sets_value() {
560+
let server = Server::new().http2_max_pending_accept_reset_streams(64);
561+
assert_eq!(
562+
server.http2_config.max_pending_accept_reset_streams,
563+
Some(64)
564+
);
565+
}
566+
}

0 commit comments

Comments
 (0)