This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients asvetlov, vstinner, yselivanov
Date 2019-06-24.13:48:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
We get a ConnectionResetError exception thanks to IocpProactor.recv() callback:

        def finish_recv(trans, key, ov):
                return ov.getresult()
            except OSError as exc:
                if exc.winerror in (_overlapped.ERROR_NETNAME_DELETED,
                    raise ConnectionResetError(*exc.args)

Would it be legit to convert ConnectionResetError to returning b'' in sock_recv()? Example with the test:

        while True:
            data = await self.loop.sock_recv(sock, DATA_SIZE)
            if not data:
            expected = bytes(islice(checker, len(data)))
            self.assertEqual(data, expected)
            size -= len(data)
        self.assertEqual(size, 0)

"if not data:" is a common test to check if we reached the end of file or if a socket has been closed by the peer, no?

Proposed patch:

diff --git a/Lib/asyncio/ b/Lib/asyncio/
index 9b8ae064a8..14b7f10729 100644
--- a/Lib/asyncio/
+++ b/Lib/asyncio/
@@ -687,10 +687,16 @@ class BaseProactorEventLoop(base_events.BaseEventLoop):
     async def sock_recv(self, sock, n):
-        return await self._proactor.recv(sock, n)
+        try:
+            return await self._proactor.recv(sock, n)
+        except (ConnectionResetError, ConnectionAbortedError):
+            return b''
     async def sock_recv_into(self, sock, buf):
-        return await self._proactor.recv_into(sock, buf)
+        try:
+            return await self._proactor.recv_into(sock, buf)
+        except (ConnectionResetError, ConnectionAbortedError):
+            return 0
     async def sock_sendall(self, sock, data):
         return await self._proactor.send(sock, data)

I'm not sure about this change.

I'm not sure about sock_recv_info(): are you suppose to truncate buf to 0 bytes in this case?
Date User Action Args
2019-06-24 13:48:19vstinnersetrecipients: + vstinner, asvetlov, yselivanov
2019-06-24 13:48:19vstinnersetmessageid: <>
2019-06-24 13:48:19vstinnerlinkissue36732 messages
2019-06-24 13:48:19vstinnercreate