diff --git a/CHANGES/8444.bugfix b/CHANGES/8444.bugfix new file mode 100644 index 00000000000..2fc1d5d829c --- /dev/null +++ b/CHANGES/8444.bugfix @@ -0,0 +1,2 @@ +Fix ``ws_connect`` not respecting ``timeout`` nor ``receive_timeout`` on WS(S) connection. +-- by :user:`arcivanov`. diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 277171a239e..f4fd64904ec 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -46,6 +46,7 @@ Anes Abismail Antoine Pietri Anton Kasyanov Anton Zhdan-Pushkin +Arcadiy Ivanov Arseny Timoniq Artem Yushkovskiy Arthur Darcet diff --git a/aiohttp/client.py b/aiohttp/client.py index 32d2c3b7119..165cd145ee4 100644 --- a/aiohttp/client.py +++ b/aiohttp/client.py @@ -922,6 +922,13 @@ async def _ws_connect( assert conn is not None conn_proto = conn.protocol assert conn_proto is not None + # For WS connection the sock_read must be either receive_timeout + # or timeout (whichever is specified), unless read_timeout is greater + conn_proto.read_timeout = ( + max(receive_timeout or timeout, conn_proto.read_timeout) + if conn_proto.read_timeout + else (receive_timeout or timeout) + ) transport = conn.transport assert transport is not None reader: FlowControlDataQueue[WSMessage] = FlowControlDataQueue( diff --git a/aiohttp/client_proto.py b/aiohttp/client_proto.py index 723f5aae5f4..a7c4b6c757d 100644 --- a/aiohttp/client_proto.py +++ b/aiohttp/client_proto.py @@ -224,6 +224,14 @@ def _reschedule_timeout(self) -> None: def start_timeout(self) -> None: self._reschedule_timeout() + @property + def read_timeout(self) -> Optional[float]: + return self._read_timeout + + @read_timeout.setter + def read_timeout(self, read_timeout: Optional[float]) -> None: + self._read_timeout = read_timeout + def _on_read_timeout(self) -> None: exc = ServerTimeoutError("Timeout on reading data from socket") self.set_exception(exc)