diff --git a/httpcore/_async/http2.py b/httpcore/_async/http2.py index dbd0beeb..50738f2e 100644 --- a/httpcore/_async/http2.py +++ b/httpcore/_async/http2.py @@ -408,8 +408,8 @@ async def _receive_remote_settings_change( async def _response_closed(self, stream_id: int) -> None: await self._max_streams_semaphore.release() - del self._events[stream_id] async with self._state_lock: + del self._events[stream_id] if self._connection_terminated and not self._events: await self.aclose() diff --git a/httpcore/_sync/http2.py b/httpcore/_sync/http2.py index ddcc1890..6dcb10b0 100644 --- a/httpcore/_sync/http2.py +++ b/httpcore/_sync/http2.py @@ -408,8 +408,8 @@ def _receive_remote_settings_change( def _response_closed(self, stream_id: int) -> None: self._max_streams_semaphore.release() - del self._events[stream_id] with self._state_lock: + del self._events[stream_id] if self._connection_terminated and not self._events: self.close()