Skip to content

gh-83037: Fix StreamWriter.wait_closed() ConnectionResetError for ProactorEventLoop #18199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

aeros
Copy link
Contributor

@aeros aeros commented Jan 27, 2020

This is one possible fix for the given issue. There's still discussion on the issue about the proper fix.

@aeros aeros changed the title Fix IocpProactor.recv() error bpo38856: Fix IocpProactor.recv() error Jan 27, 2020
@aeros aeros changed the title bpo38856: Fix IocpProactor.recv() error bpo-38856: Fix IocpProactor.recv() error Jan 27, 2020
@aeros aeros changed the title bpo-38856: Fix IocpProactor.recv() error bpo-38856: Fix StreamWriter.wait_closed() ConnectionResetError for ProactorEventLoop Jan 27, 2020
@aeros aeros force-pushed the bpo38856-fix-IocpProactor.recv-error branch from 6a66228 to ddfa933 Compare January 27, 2020 09:26
@aeros aeros requested a review from asvetlov January 27, 2020 09:54
@aeros aeros marked this pull request as ready for review January 27, 2020 10:02
@aeros aeros requested a review from 1st1 as a code owner January 27, 2020 10:02
@aeros
Copy link
Contributor Author

aeros commented Jan 27, 2020

I'll leave the DO-NOT-MERGE label until someone experienced with the win32 API and its interaction with asyncio's streams API (such as @asvetlov) gets a chance to review the PR.

@aeros
Copy link
Contributor Author

aeros commented Mar 22, 2020

Ping @asvetlov

@basnijholt
Copy link

I am getting this error:

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.

@aeros
Copy link
Contributor Author

aeros commented Jul 15, 2020

Thanks for testing it out @basnijholt, I was not comfortable yet with merging this patch yet. It seems like this issue will require some further investigation.

@basnijholt
Copy link

I now realize this PR addresses only the loop used for Windows, I observe this issue on Linux.

@dmitryduka
Copy link

Similar issue happens in other functions (not covered in this PR) in Python 3.8.13:

Traceback (most recent call last):
  File "asyncio\windows_events.py", line 566, in accept_coro
  File "asyncio\windows_events.py", line 812, in _poll
  File "asyncio\windows_events.py", line 555, in finish_accept
OSError: [WinError 64] The specified network name is no longer available
2022-05-16 18:30:25,138	asyncio	ERROR	Accept failed on a socket
socket: <asyncio.TransportSocket fd=812, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('127.0.0.1', 8891)>
Traceback (most recent call last):
  File "asyncio\proactor_events.py", line 818, in loop
  File "asyncio\windows_events.py", line 566, in accept_coro
  File "asyncio\windows_events.py", line 812, in _poll
  File "asyncio\windows_events.py", line 555, in finish_accept
OSError: [WinError 64] The specified network name is no longer available

@Cacsjep
Copy link

Cacsjep commented Jun 17, 2022

I would ask if I can help, we also discovering ERR_NETNAME_DELETE while accpeting new connetions and this leads into closing listening socket of BaseProactorEventLoop, what is really bad.

@gvanrossum gvanrossum requested a review from willingc as a code owner May 23, 2023 17:10
@gvanrossum gvanrossum changed the title bpo-38856: Fix StreamWriter.wait_closed() ConnectionResetError for ProactorEventLoop gh-83037: Fix StreamWriter.wait_closed() ConnectionResetError for ProactorEventLoop May 23, 2023
@gvanrossum gvanrossum requested review from eryksun and removed request for 1st1 and asvetlov May 23, 2023 17:14
@kumaraditya303 kumaraditya303 removed their request for review August 20, 2023 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants