@@ -366,7 +366,11 @@ impl<B> DynStreams<'_, B> {
366366 me. recv_eof ( self . send_buffer , clear_pending_accept)
367367 }
368368
369- pub fn send_reset ( & mut self , id : StreamId , reason : Reason ) {
369+ pub fn send_reset (
370+ & mut self ,
371+ id : StreamId ,
372+ reason : Reason ,
373+ ) -> Result < ( ) , crate :: proto:: error:: GoAway > {
370374 let mut me = self . inner . lock ( ) . unwrap ( ) ;
371375 me. send_reset ( self . send_buffer , id, reason)
372376 }
@@ -637,15 +641,23 @@ impl Inner {
637641 // The remote may send window updates for streams that the local now
638642 // considers closed. It's ok...
639643 if let Some ( mut stream) = self . store . find_mut ( & id) {
640- // This result is ignored as there is nothing to do when there
641- // is an error. The stream is reset by the function on error and
642- // the error is informational.
643- let _ = self . actions . send . recv_stream_window_update (
644- frame. size_increment ( ) ,
644+ let res = self
645+ . actions
646+ . send
647+ . recv_stream_window_update (
648+ frame. size_increment ( ) ,
649+ send_buffer,
650+ & mut stream,
651+ & mut self . counts ,
652+ & mut self . actions . task ,
653+ )
654+ . map_err ( |reason| Error :: library_reset ( id, reason) ) ;
655+
656+ return self . actions . reset_on_recv_stream_err (
645657 send_buffer,
646658 & mut stream,
647659 & mut self . counts ,
648- & mut self . actions . task ,
660+ res ,
649661 ) ;
650662 } else {
651663 self . actions
@@ -882,7 +894,12 @@ impl Inner {
882894 Poll :: Ready ( Ok ( ( ) ) )
883895 }
884896
885- fn send_reset < B > ( & mut self , send_buffer : & SendBuffer < B > , id : StreamId , reason : Reason ) {
897+ fn send_reset < B > (
898+ & mut self ,
899+ send_buffer : & SendBuffer < B > ,
900+ id : StreamId ,
901+ reason : Reason ,
902+ ) -> Result < ( ) , crate :: proto:: error:: GoAway > {
886903 let key = match self . store . find_entry ( id) {
887904 Entry :: Occupied ( e) => e. key ( ) ,
888905 Entry :: Vacant ( e) => {
@@ -923,7 +940,7 @@ impl Inner {
923940 Initiator :: Library ,
924941 & mut self . counts ,
925942 send_buffer,
926- ) ;
943+ )
927944 }
928945}
929946
@@ -1095,8 +1112,20 @@ impl<B> StreamRef<B> {
10951112 let mut send_buffer = self . send_buffer . inner . lock ( ) . unwrap ( ) ;
10961113 let send_buffer = & mut * send_buffer;
10971114
1098- me. actions
1099- . send_reset ( stream, reason, Initiator :: User , & mut me. counts , send_buffer) ;
1115+ match me
1116+ . actions
1117+ . send_reset ( stream, reason, Initiator :: User , & mut me. counts , send_buffer)
1118+ {
1119+ Ok ( ( ) ) => ( ) ,
1120+ Err ( crate :: proto:: error:: GoAway { .. } ) => {
1121+ // this should never happen, because Initiator::User resets do
1122+ // not count toward the local limit.
1123+ // we could perhaps make this state impossible, if we made the
1124+ // initiator argument a generic, and so this could return
1125+ // Infallible instead of an impossible GoAway, but oh well.
1126+ unreachable ! ( "Initiator::User should not error sending reset" ) ;
1127+ }
1128+ }
11001129 }
11011130
11021131 pub fn send_response (
@@ -1517,8 +1546,23 @@ impl Actions {
15171546 initiator : Initiator ,
15181547 counts : & mut Counts ,
15191548 send_buffer : & mut Buffer < Frame < B > > ,
1520- ) {
1549+ ) -> Result < ( ) , crate :: proto :: error :: GoAway > {
15211550 counts. transition ( stream, |counts, stream| {
1551+ if initiator. is_library ( ) {
1552+ if counts. can_inc_num_local_error_resets ( ) {
1553+ counts. inc_num_local_error_resets ( ) ;
1554+ } else {
1555+ tracing:: warn!(
1556+ "locally-reset streams reached limit ({:?})" ,
1557+ counts. max_local_error_resets( ) . unwrap( ) ,
1558+ ) ;
1559+ return Err ( crate :: proto:: error:: GoAway {
1560+ reason : Reason :: ENHANCE_YOUR_CALM ,
1561+ debug_data : "too_many_internal_resets" . into ( ) ,
1562+ } ) ;
1563+ }
1564+ }
1565+
15221566 self . send . send_reset (
15231567 reason,
15241568 initiator,
@@ -1530,7 +1574,9 @@ impl Actions {
15301574 self . recv . enqueue_reset_expiration ( stream, counts) ;
15311575 // if a RecvStream is parked, ensure it's notified
15321576 stream. notify_recv ( ) ;
1533- } ) ;
1577+
1578+ Ok ( ( ) )
1579+ } )
15341580 }
15351581
15361582 fn reset_on_recv_stream_err < B > (
0 commit comments