@@ -240,6 +240,10 @@ pub struct Builder {
240240 /// Maximum number of locally reset streams to keep at a time.
241241 reset_stream_max : usize ,
242242
243+ /// Maximum number of remotely reset streams to allow in the pending
244+ /// accept queue.
245+ pending_accept_reset_stream_max : usize ,
246+
243247 /// Initial `Settings` frame to send as part of the handshake.
244248 settings : Settings ,
245249
@@ -642,6 +646,7 @@ impl Builder {
642646 Builder {
643647 reset_stream_duration : Duration :: from_secs ( proto:: DEFAULT_RESET_STREAM_SECS ) ,
644648 reset_stream_max : proto:: DEFAULT_RESET_STREAM_MAX ,
649+ pending_accept_reset_stream_max : proto:: DEFAULT_REMOTE_RESET_STREAM_MAX ,
645650 settings : Settings :: default ( ) ,
646651 initial_target_connection_window_size : None ,
647652 max_send_buffer_size : proto:: DEFAULT_MAX_SEND_BUFFER_SIZE ,
@@ -882,6 +887,49 @@ impl Builder {
882887 self
883888 }
884889
890+ /// Sets the maximum number of pending-accept remotely-reset streams.
891+ ///
892+ /// Streams that have been received by the peer, but not accepted by the
893+ /// user, can also receive a RST_STREAM. This is a legitimate pattern: one
894+ /// could send a request and then shortly after, realize it is not needed,
895+ /// sending a CANCEL.
896+ ///
897+ /// However, since those streams are now "closed", they don't count towards
898+ /// the max concurrent streams. So, they will sit in the accept queue,
899+ /// using memory.
900+ ///
901+ /// When the number of remotely-reset streams sitting in the pending-accept
902+ /// queue reaches this maximum value, a connection error with the code of
903+ /// `ENHANCE_YOUR_CALM` will be sent to the peer, and returned by the
904+ /// `Future`.
905+ ///
906+ /// The default value is 20.
907+ ///
908+ /// # Examples
909+ ///
910+ ///
911+ /// ```
912+ /// # use tokio::io::{AsyncRead, AsyncWrite};
913+ /// # use h2::server::*;
914+ /// #
915+ /// # fn doc<T: AsyncRead + AsyncWrite + Unpin>(my_io: T)
916+ /// # -> Handshake<T>
917+ /// # {
918+ /// // `server_fut` is a future representing the completion of the HTTP/2
919+ /// // handshake.
920+ /// let server_fut = Builder::new()
921+ /// .max_pending_accept_reset_streams(100)
922+ /// .handshake(my_io);
923+ /// # server_fut
924+ /// # }
925+ /// #
926+ /// # pub fn main() {}
927+ /// ```
928+ pub fn max_pending_accept_reset_streams ( & mut self , max : usize ) -> & mut Self {
929+ self . pending_accept_reset_stream_max = max;
930+ self
931+ }
932+
885933 /// Sets the maximum send buffer size per stream.
886934 ///
887935 /// Once a stream has buffered up to (or over) the maximum, the stream's
@@ -1312,6 +1360,7 @@ where
13121360 max_send_buffer_size : self . builder . max_send_buffer_size ,
13131361 reset_stream_duration : self . builder . reset_stream_duration ,
13141362 reset_stream_max : self . builder . reset_stream_max ,
1363+ remote_reset_stream_max : self . builder . pending_accept_reset_stream_max ,
13151364 settings : self . builder . settings . clone ( ) ,
13161365 } ,
13171366 ) ;
0 commit comments