Skip to content

Commit 59513ce

Browse files
authored
fix: adjust expiring reset stream limits (#858)
h2 has mechanisms to remember a local reset stream for some time afterward, to support what it says in RFC 9113 SS 5.4.2: > A RST_STREAM is the last frame that an endpoint can send on a stream. The peer that sends the RST_STREAM frame MUST be prepared to receive any frames that were sent or enqueued for sending by the remote peer. These frames can be ignored, except where they modify connection state (such as the state maintained for field section compression (Section 4.3) or flow control). > > Normally, an endpoint SHOULD NOT send more than one RST_STREAM frame for any stream. However, an endpoint MAY send additional RST_STREAM frames if it receives frames on a closed stream after more than a round-trip time. This behavior is permitted to deal with misbehaving implementations. We don't want to remember the streams for forever, that would cause memory to grow. Nor do we want to accept frames on those streams without limit, since that would waste resources. Thus, we limit how much we remember, but stream count and duration. This changes the defaults to be something perhaps a little more reasonable: - 50 streams, a conservative amount of half of the recommending minimum concurrent streams any remote SHOULD support. - 1 second, since the RFC only suggests about 1 RTT. We don't keep track of RTT, but even p99 RTT is around 250ms, maybe 500ms. One possibility is having different values for server and client, since servers are usually more interested in constraining resources, but at the same time, many servers also contain clients. cc #856
1 parent c85d1e8 commit 59513ce

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

src/client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ impl Builder {
923923
/// received for that stream will result in a connection level protocol
924924
/// error, forcing the connection to terminate.
925925
///
926-
/// The default value is 10.
926+
/// The default value is currently 50.
927927
///
928928
/// # Examples
929929
///
@@ -968,7 +968,7 @@ impl Builder {
968968
/// received for that stream will result in a connection level protocol
969969
/// error, forcing the connection to terminate.
970970
///
971-
/// The default value is 30 seconds.
971+
/// The default value is currently 1 second.
972972
///
973973
/// # Examples
974974
///

src/proto/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ pub type WindowSize = u32;
3333
pub const MAX_WINDOW_SIZE: WindowSize = (1 << 31) - 1; // i32::MAX as u32
3434
pub const DEFAULT_REMOTE_RESET_STREAM_MAX: usize = 20;
3535
pub const DEFAULT_LOCAL_RESET_COUNT_MAX: usize = 1024;
36-
pub const DEFAULT_RESET_STREAM_MAX: usize = 10;
37-
pub const DEFAULT_RESET_STREAM_SECS: u64 = 30;
36+
// RFC 9113 suggests allowing at minimum 100 streams, it seems reasonable to
37+
// by default allow a portion of that to be remembered as reset for some time.
38+
pub const DEFAULT_RESET_STREAM_MAX: usize = 50;
39+
// RFC 9113#5.4.2 suggests ~1 RTT. We don't track that closely, but use a
40+
// reasonable guess of the average here.
41+
pub const DEFAULT_RESET_STREAM_SECS: u64 = 1;
3842
pub const DEFAULT_MAX_SEND_BUFFER_SIZE: usize = 1024 * 400;

src/proto/streams/recv.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -912,11 +912,15 @@ impl Recv {
912912
return;
913913
}
914914

915-
tracing::trace!("enqueue_reset_expiration; {:?}", stream.id);
916-
917915
if counts.can_inc_num_reset_streams() {
918916
counts.inc_num_reset_streams();
917+
tracing::trace!("enqueue_reset_expiration; added {:?}", stream.id);
919918
self.pending_reset_expired.push(stream);
919+
} else {
920+
tracing::trace!(
921+
"enqueue_reset_expiration; dropped {:?}, over max_concurrent_reset_streams",
922+
stream.id
923+
);
920924
}
921925
}
922926

src/server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ impl Builder {
868868
/// received for that stream will result in a connection level protocol
869869
/// error, forcing the connection to terminate.
870870
///
871-
/// The default value is 10.
871+
/// The default value is currently 50.
872872
///
873873
/// # Examples
874874
///
@@ -993,7 +993,7 @@ impl Builder {
993993
/// received for that stream will result in a connection level protocol
994994
/// error, forcing the connection to terminate.
995995
///
996-
/// The default value is 30 seconds.
996+
/// The default value is currently 1 second.
997997
///
998998
/// # Examples
999999
///

0 commit comments

Comments
 (0)