Skip to content

Commit

Permalink
Stream unpauses protocol before releasing connection (#10171)
Browse files Browse the repository at this point in the history
  • Loading branch information
javitonino authored Dec 18, 2024
1 parent e45c3b8 commit 5185f93
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGES/10169.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fixed a hang where a connection previously used for a streaming
download could be returned to the pool in a paused state.
-- by :user:`javitonino`.
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ Jan Buchar
Jan Gosmann
Jarno Elonen
Jashandeep Sohi
Javier Torres
Jean-Baptiste Estival
Jens Steinhauser
Jeonghun Lee
Expand Down
3 changes: 3 additions & 0 deletions aiohttp/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ def feed_eof(self) -> None:
self._eof_waiter = None
set_result(waiter, None)

if self._protocol._reading_paused:
self._protocol.resume_reading()

for cb in self._eof_callbacks:
try:
cb()
Expand Down
22 changes: 22 additions & 0 deletions tests/test_flowcontrol_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,25 @@ async def test_read_nowait(self, stream: streams.StreamReader) -> None:
res = stream.read_nowait(5)
assert res == b""
assert stream._protocol.resume_reading.call_count == 1 # type: ignore[attr-defined]

async def test_resumed_on_eof(self, stream: streams.StreamReader) -> None:
stream.feed_data(b"data")
assert stream._protocol.pause_reading.call_count == 1 # type: ignore[attr-defined]
assert stream._protocol.resume_reading.call_count == 0 # type: ignore[attr-defined]
stream._protocol._reading_paused = True

stream.feed_eof()
assert stream._protocol.resume_reading.call_count == 1 # type: ignore[attr-defined]


async def test_stream_reader_eof_when_full() -> None:
loop = asyncio.get_event_loop()
protocol = BaseProtocol(loop=loop)
protocol.transport = asyncio.Transport()
stream = streams.StreamReader(protocol, 1024, loop=loop)

data_len = stream._high_water + 1
stream.feed_data(b"0" * data_len)
assert protocol._reading_paused
stream.feed_eof()
assert not protocol._reading_paused

0 comments on commit 5185f93

Please sign in to comment.