From c44ecdf687897a20f11d0c5212b51e8d31f6100a Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Mon, 19 Oct 2015 11:49:30 -0700 Subject: Issue #25441: asyncio: Raise error from drain() when socket is closed. --- Lib/asyncio/streams.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'Lib/asyncio') diff --git a/Lib/asyncio/streams.py b/Lib/asyncio/streams.py index bb9fb313af..fb786ed864 100644 --- a/Lib/asyncio/streams.py +++ b/Lib/asyncio/streams.py @@ -301,6 +301,15 @@ class StreamWriter: exc = self._reader.exception() if exc is not None: raise exc + if self._transport is not None: + if self._transport._closing: + # Yield to the event loop so connection_lost() may be + # called. Without this, _drain_helper() would return + # immediately, and code that calls + # write(...); yield from drain() + # in a loop would never call connection_lost(), so it + # would not see an error when the socket is closed. + yield yield from self._protocol._drain_helper() -- cgit v1.2.1