From 849228de96bbe32a8d61d56718ddb67b4ef2ad28 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 1 Dec 2024 19:06:29 -0600 Subject: [PATCH] Avoid calling len on the same data in the stream reader twice (#10088) (cherry picked from commit 29c3ca93a4d1793c60d33038151228962f8b6f78) --- aiohttp/streams.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/aiohttp/streams.py b/aiohttp/streams.py index b97846171b1..029d577b88c 100644 --- a/aiohttp/streams.py +++ b/aiohttp/streams.py @@ -517,8 +517,9 @@ def _read_nowait_chunk(self, n: int) -> bytes: else: data = self._buffer.popleft() - self._size -= len(data) - self._cursor += len(data) + data_len = len(data) + self._size -= data_len + self._cursor += data_len chunk_splits = self._http_chunk_splits # Prevent memory leak: drop useless chunk splits