[issue27500] ProactorEventLoop cannot open connection to ::1
bay
report at bugs.python.org
Thu Jun 28 07:37:33 EDT 2018
bay <bay at hackerdom.ru> added the comment:
The bug is reproducible on Python 3.7. The connect call always fails when I
try to use connect to any IPv6 address with ProactorEventLoop.
The bug can be bypassed by adding "%0" to the IPv6 address. This will cause
to trigger this if construction:
https://github.com/python/cpython/blob/e76ac9d4ef77b74ea7de768f4de7c38893fad539/Lib/asyncio/base_events.py#L133
As mentioned by Sebastian, it happen because the _ipaddr_info function returns
only the host and the port for IPv6: return af, type, proto, '', (host, port)
https://github.com/python/cpython/blob/e76ac9d4ef77b74ea7de768f4de7c38893fad539/Lib/asyncio/base_events.py#L142
This (host, port) tuple used in ConnectEx call, but it expect 4-element tuple
to connect IPv6:
https://github.com/python/cpython/blob/55edd0c185ad2d895b5d73e47d67049bc156b654/Modules/overlapped.c#L1090
Instead it tries to connect, using IPv4 and fails.
The bug can be fixed by doing the following:
if af == socket.AF_INET6:
return af, type, proto, '', (host, port, 0, 0)
else:
return af, type, proto, '', (host, port)
instead of
return af, type, proto, '', (host, port)
in
https://github.com/python/cpython/blob/e76ac9d4ef77b74ea7de768f4de7c38893fad539/Lib/asyncio/base_events.py#L142
----------
nosy: +bay
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue27500>
_______________________________________
More information about the Python-bugs-list
mailing list