Skip to content

Commit 61c7eef

Browse files
[PR #9803/fc912352 backport][3.11] Small performance improvement to drain (#9807)
Co-authored-by: J. Nick Koston <[email protected]>
1 parent 255bf5c commit 61c7eef

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

aiohttp/base_protocol.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def connection_lost(self, exc: Optional[BaseException]) -> None:
8989
)
9090

9191
async def _drain_helper(self) -> None:
92-
if not self.connected:
92+
if self.transport is None:
9393
raise ClientConnectionResetError("Connection lost")
9494
if not self._paused:
9595
return

aiohttp/http_writer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,9 @@ async def drain(self) -> None:
172172
await w.write(data)
173173
await w.drain()
174174
"""
175-
if self._protocol.transport is not None:
176-
await self._protocol._drain_helper()
175+
protocol = self._protocol
176+
if protocol.transport is not None and protocol._paused:
177+
await protocol._drain_helper()
177178

178179

179180
def _safe_header(string: str) -> str:

tests/test_benchmarks_client_request.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class MockProtocol(asyncio.BaseProtocol):
8888

8989
def __init__(self) -> None:
9090
self.transport = MockTransport()
91+
self._paused = False
9192

9293
@property
9394
def writing_paused(self) -> bool:

0 commit comments

Comments
 (0)