diff --git a/src/httpcore2/httpcore2/_async/http2.py b/src/httpcore2/httpcore2/_async/http2.py index ae3e764c..7cea171f 100644 --- a/src/httpcore2/httpcore2/_async/http2.py +++ b/src/httpcore2/httpcore2/_async/http2.py @@ -377,8 +377,8 @@ async def _receive_remote_settings_change(self, event: h2.events.RemoteSettingsC 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/src/httpcore2/httpcore2/_sync/http2.py b/src/httpcore2/httpcore2/_sync/http2.py index 0512c4a2..12d37de4 100644 --- a/src/httpcore2/httpcore2/_sync/http2.py +++ b/src/httpcore2/httpcore2/_sync/http2.py @@ -377,8 +377,8 @@ def _receive_remote_settings_change(self, event: h2.events.RemoteSettingsChanged 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()