File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -401,6 +401,9 @@ async def _receive_remote_settings_change(self, event: h2.events.Event) -> None:
401
401
await self ._max_streams_semaphore .acquire ()
402
402
self ._max_streams -= 1
403
403
404
+ async def _reset_steam (self , stream_id : int , error_code : int ) -> None :
405
+ self ._h2_state .reset_stream (stream_id = stream_id , error_code = error_code )
406
+
404
407
async def _response_closed (self , stream_id : int ) -> None :
405
408
await self ._max_streams_semaphore .release ()
406
409
del self ._events [stream_id ]
@@ -578,6 +581,12 @@ async def __aiter__(self) -> typing.AsyncIterator[bytes]:
578
581
# we want to close the response (and possibly the connection)
579
582
# before raising that exception.
580
583
with AsyncShieldCancellation ():
584
+ # need send cancel frame when the exception is not from remote peer.
585
+ if not isinstance (exc , RemoteProtocolError ):
586
+ await self ._connection ._reset_steam (
587
+ stream_id = self ._stream_id ,
588
+ error_code = h2 .settings .ErrorCodes .CANCEL ,
589
+ )
581
590
await self .aclose ()
582
591
raise exc
583
592
Original file line number Diff line number Diff line change @@ -401,6 +401,9 @@ def _receive_remote_settings_change(self, event: h2.events.Event) -> None:
401
401
self ._max_streams_semaphore .acquire ()
402
402
self ._max_streams -= 1
403
403
404
+ def _reset_steam (self , stream_id : int , error_code : int ) -> None :
405
+ self ._h2_state .reset_stream (stream_id = stream_id , error_code = error_code )
406
+
404
407
def _response_closed (self , stream_id : int ) -> None :
405
408
self ._max_streams_semaphore .release ()
406
409
del self ._events [stream_id ]
@@ -578,6 +581,12 @@ def __iter__(self) -> typing.Iterator[bytes]:
578
581
# we want to close the response (and possibly the connection)
579
582
# before raising that exception.
580
583
with ShieldCancellation ():
584
+ # need send cancel frame when the exception is not from remote peer.
585
+ if not isinstance (exc , RemoteProtocolError ):
586
+ self ._connection ._reset_steam (
587
+ stream_id = self ._stream_id ,
588
+ error_code = h2 .settings .ErrorCodes .CANCEL ,
589
+ )
581
590
self .close ()
582
591
raise exc
583
592
You can’t perform that action at this time.
0 commit comments