Skip to content

Commit

Permalink
馃惤 Fix memory leak in chunked streams handling code (#3631)
Browse files Browse the repository at this point in the history
  • Loading branch information
socketpair committed Mar 3, 2019
1 parent 398b5ba commit e9ac7d1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES/3631.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cleanup per-chunk data in generic data read. Memory leak fixed.
5 changes: 5 additions & 0 deletions aiohttp/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,11 @@ def _read_nowait_chunk(self, n: int) -> bytes:
self._size -= len(data)
self._cursor += len(data)

chunk_splits = self._http_chunk_splits
# Prevent memory leak: drop useless chunk splits
while chunk_splits and chunk_splits[0] < self._cursor:
chunk_splits.pop()

if self._size < self._low_water and self._protocol._reading_paused:
self._protocol.resume_reading()
return data
Expand Down

0 comments on commit e9ac7d1

Please sign in to comment.