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 0b9f824
Show file tree
Hide file tree
Showing 2 changed files with 5 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.
4 changes: 4 additions & 0 deletions aiohttp/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,10 @@ def _read_nowait_chunk(self, n: int) -> bytes:
self._size -= len(data)
self._cursor += len(data)

# Prevent memory leak: drop useless chunk splits
while self._http_chunk_splits and self._http_chunk_splits[0] < self._cursor:
self._http_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 0b9f824

Please sign in to comment.