diff --git a/Lib/asyncio/proactor_events.py b/Lib/asyncio/proactor_events.py index 8338449aaa0a3e..55a031ab47bc8d 100644 --- a/Lib/asyncio/proactor_events.py +++ b/Lib/asyncio/proactor_events.py @@ -765,7 +765,14 @@ def _make_self_pipe(self): def _loop_self_reading(self, f=None): try: if f is not None: - f.result() # may raise + try: + f.result() # may raise + except ConnectionResetError: + # when run_forever exits, the done callback added at + # the end of this function may still be pending and a subclass + # may have also cancelled the future. this will result in a + # spurious ConnectionResetError. ignore that error. + pass f = self._proactor.recv(self._ssock, 4096) except exceptions.CancelledError: # _close_self_pipe() has been called, stop waiting for data