From 9924db4d6ac26c6f03a3b797c13c7871d2cc93e9 Mon Sep 17 00:00:00 2001 From: MarkLux Date: Mon, 19 Aug 2024 21:17:47 +0800 Subject: [PATCH] fix(h2_connection_reset): add stream reset when client cancel the request --- httpcore/_async/http2.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/httpcore/_async/http2.py b/httpcore/_async/http2.py index c201ee4cb..041e9e74f 100644 --- a/httpcore/_async/http2.py +++ b/httpcore/_async/http2.py @@ -404,6 +404,14 @@ async def _receive_remote_settings_change(self, event: h2.events.Event) -> None: async def _response_closed(self, stream_id: int) -> None: await self._max_streams_semaphore.release() del self._events[stream_id] + + stream = self._h2_state._get_stream_by_id(stream_id=stream_id) + if stream and not stream.closed: + # stream closed by client cancel, send a RstStream frame with CancelCode to server + self._h2_state.reset_stream( + stream_id=stream_id, error_code=h2.settings.ErrorCodes.CANCEL + ) + async with self._state_lock: if self._connection_terminated and not self._events: await self.aclose()