asyncio: Fix _UnixWritePipeTransport, raise BrokenPipeError when the pipe is
closed, but only if there was pending write
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py
index ac764f8..98fddde 100644
--- a/Lib/asyncio/unix_events.py
+++ b/Lib/asyncio/unix_events.py
@@ -283,7 +283,10 @@
 
     def _read_ready(self):
         # Pipe was closed by peer.
-        self._close()
+        if self._buffer:
+            self._close(BrokenPipeError())
+        else:
+            self._close()
 
     def write(self, data):
         assert isinstance(data, (bytes, bytearray, memoryview)), repr(data)