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.

classification
Title: asyncio ProactorEventLoop: wait_closed() can raise ConnectionResetError
Type: Stage: patch review
Components: asyncio, Windows Versions: Python 3.9, Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: asvetlov Nosy List: aeros, asvetlov, basnijholt, cmeyer, lukasz.langa, paul.moore, seer, steve.dower, tim.golden, yselivanov, zach.ware
Priority: high Keywords: patch

Created on 2019-11-19 22:06 by yselivanov, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 18199 open aeros, 2020-01-27 08:40
Messages (10)
msg356996 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2019-11-19 22:06
The exception should probably be just ignored.  Andrew, thoughts?

Here's an example error traceback:

      Traceback (most recent call last):
        File "c:\projects\asyncpg\asyncpg\connection.py", line 1227, in _cancel
          await w.wait_closed()
        File "C:\Python38\lib\asyncio\streams.py", line 376, in wait_closed
          await self._protocol._get_close_waiter(self)
        File "c:\projects\asyncpg\asyncpg\connection.py", line 1202, in _cancel
          await r.read()  # Wait until EOF
        File "C:\Python38\lib\asyncio\streams.py", line 694, in read
          block = await self.read(self._limit)
        File "C:\Python38\lib\asyncio\streams.py", line 701, in read
          await self._wait_for_data('read')
        File "C:\Python38\lib\asyncio\streams.py", line 534, in _wait_for_data
          await self._waiter
        File "C:\Python38\lib\asyncio\proactor_events.py", line 280, in _loop_reading
          data = fut.result()
        File "C:\Python38\lib\asyncio\windows_events.py", line 808, in _poll
          value = callback(transferred, key, ov)
        File "C:\Python38\lib\asyncio\windows_events.py", line 457, in finish_recv
          raise ConnectionResetError(*exc.args)
      ConnectionResetError: [WinError 64] The specified network name is no longer available
msg358097 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2019-12-09 14:18
Note: this is going to miss Python 3.8.1 as I'm releasing 3.8.1rc1 right now.  Please address this before 3.8.2 (due in February).
msg358109 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2019-12-09 15:01
Sorry, I've missed this issue.
I'll address it in a while.
msg360410 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-01-21 17:23
Why is this issue marked as a release blocker? Is it a Python 3.8 regression, or just a regular bug?
msg360742 - (view) Author: Kyle Stanley (aeros) * (Python committer) Date: 2020-01-27 08:22
> The exception should probably be just ignored.

It looks like the "ERROR_NETNAME_DELETED" (win32 error 64) exception is already ignored in multiprocessing's connection.wait(): https://github.com/python/cpython/blob/bccacd19fa7b56dcf2fbfab15992b6b94ab6666b/Lib/multiprocessing/connection.py#L857. Would it be appropriate to ignore it here as well?

I think that we should still retain the ConnectionResetError for "ERROR_OPERATION_ABORTED", but just specifically ignore "ERROR_NETNAME_DELETED". Ignoring "ERROR_OPERATION_ABORTED" doesn't seem correct here since it's relied on for cancelling file I/O (see https://docs.microsoft.com/en-us/windows/win32/fileio/canceling-pending-i-o-operations).

The patch should be straightforward. I'll test it locally and then open a PR, unless Andrew is currently working on it.
msg362633 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2020-02-25 12:03
Downgrading priority on this, agreed with Victor.
msg364242 - (view) Author: Ido Michael (Ido Michael) * Date: 2020-03-15 15:50
Is this open for a PR?
msg364250 - (view) Author: Kyle Stanley (aeros) * (Python committer) Date: 2020-03-15 19:38
> Is this open for a PR?

I opened a PR for this issue a bit ago (applies Yury's suggestion of suppressing the exception), just waiting on review from Andrew when he finds the time to do so.
msg373755 - (view) Author: Bas Nijholt (basnijholt) Date: 2020-07-16 15:13
I have noticed the following on Linux too:
```
Traceback (most recent call last):
  File "/config/custom_components/kef_custom/aiokef.py", line 327, in _disconnect
    await self._writer.wait_closed()
  File "/usr/local/lib/python3.7/asyncio/streams.py", line 323, in wait_closed
    await self._protocol._closed
  File "/config/custom_components/kef_custom/aiokef.py", line 299, in _send_message
    await self._writer.drain()
  File "/usr/local/lib/python3.7/asyncio/streams.py", line 339, in drain
    raise exc
  File "/usr/local/lib/python3.7/asyncio/selector_events.py", line 814, in _read_ready__data_received
    data = self._sock.recv(self.max_size)
ConnectionResetError: [Errno 104] Connection reset by peer
```
after which every invocation of `await asyncio.open_connection` fails with `ConnectionRefusedError` until I restart the entire Python process.

IIUC, just ignoring the exception will not be enough.

This issue is about the `ProactorEventLoop` for Windows specifically, however, my process uses the default event loop on Linux.
msg399483 - (view) Author: Artem (seer) Date: 2021-08-12 21:30
Python 3.9.6 Linux same issue.
History
Date User Action Args
2022-04-11 14:59:23adminsetgithub: 83037
2021-08-12 21:30:37seersetnosy: + seer

messages: + msg399483
versions: + Python 3.9
2020-07-16 17:38:35cmeyersetnosy: + cmeyer
2020-07-16 15:13:02basnijholtsetnosy: + basnijholt
messages: + msg373755
2020-03-22 21:42:47Ido Michaelsetnosy: - Ido Michael
2020-03-16 13:39:05vstinnersetnosy: - vstinner
2020-03-15 19:38:56aerossetmessages: + msg364250
2020-03-15 15:50:33Ido Michaelsetnosy: + Ido Michael
messages: + msg364242
2020-02-25 12:03:54lukasz.langasetpriority: release blocker -> high

messages: + msg362633
2020-01-27 08:40:14aerossetkeywords: + patch
stage: patch review
pull_requests: + pull_request17577
2020-01-27 08:22:16aerossetnosy: + aeros
messages: + msg360742
2020-01-21 17:25:24vstinnersetnosy: + paul.moore, tim.golden, zach.ware, steve.dower
components: + Windows, asyncio
2020-01-21 17:25:08vstinnersettitle: wait_closed() can raise ConnectionResetError -> asyncio ProactorEventLoop: wait_closed() can raise ConnectionResetError
2020-01-21 17:23:34vstinnersetnosy: + vstinner
messages: + msg360410
2019-12-09 15:01:41asvetlovsetassignee: asvetlov
2019-12-09 15:01:32asvetlovsetmessages: + msg358109
2019-12-09 14:18:37lukasz.langasetmessages: + msg358097
2019-11-19 22:06:26yselivanovcreate