Skip to content

Commit

Permalink
Stream unpauses protocol before releasing connection (fixes aio-libs#…
Browse files Browse the repository at this point in the history
  • Loading branch information
javitonino committed Dec 17, 2024
1 parent 0070045 commit 247df64
Show file tree
Hide file tree
Showing 3 changed files with 28 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`.
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
assert stream._protocol.resume_reading.call_count == 0
stream._protocol._reading_paused = True

stream.feed_eof()
assert stream._protocol.resume_reading.call_count == 1


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 247df64

Please sign in to comment.