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
asyncio open_connection fails when a socket is explicitly closed #87419
Comments
Python 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] In [1]: import socket
...: s1, s2 = socket.socketpair()
...: import asyncio
...: async def test():
...: r1, w1 = await asyncio.open_connection(sock=s1)
...: r2, w2 = await asyncio.open_connection(sock=s2)
...: s1.close()
...: asyncio.run(test())
Exception in callback _ProactorBasePipeTransport._call_connection_lost(ConnectionAbo...e, 1236, None))
handle: <Handle _ProactorBasePipeTransport._call_connection_lost(ConnectionAbo...e, 1236, None))>
Traceback (most recent call last):
File "c:\python39\lib\asyncio\events.py", line 80, in _run
self._context.run(self._callback, *self._args)
File "c:\python39\lib\asyncio\proactor_events.py", line 162, in _call_connection_lost
self._sock.shutdown(socket.SHUT_RDWR)
OSError: [WinError 10038] An operation was attempted on something that is not a socket |
I cannot reproduce on a Debian machine. Seems to be a Windows component issue? |
It reproduced on a windows machine |
Please consider passing 'sock' argument as the ownership transfer. You should not perform any action on 'sock' object directly anymore. |
We are hitting the same traceback with mitmproxy on Windows without ever passing a socket object to open_connection. In other words, this can be triggered without performing any action on 'sock' due to some race conditions in the Windows network stack. I unfortunately don't have a better repro for that race other than what Daniel provided. |
asvetlov: Sorry if I articulated myself badly, but I do think this is a valid bug. It's unfortunately hard to provide a better repro (I tried), but we are hitting this regularly when mitmproxy is accepting connections under heavy load. We're just calling Here are some observations that are true for all crashes:
An obvious fix without understanding the root cause would be to check fileno in cpython/Lib/asyncio/proactor_events.py Line 161 in d929aa7
[1] cpython/Lib/asyncio/proactor_events.py Lines 102 to 116 in d929aa7
|
Maximilian, thanks for the investigation. A check for 'fileno != -1' seems correct to me. |
Thanks! |
Thank you for the super quick turnaround. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: