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.

Title: asyncio: create_connection cannot handle IPv6 link-local addresses anymore (linux)
Type: Stage: resolved
Components: asyncio Versions: Python 3.7
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Leonardo Mörlein, asvetlov, twisteroid ambassador, yselivanov
Priority: normal Keywords:

Created on 2019-02-21 19:13 by Leonardo Mörlein, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (5)
msg336253 - (view) Author: Leonardo Mörlein (Leonardo Mörlein) Date: 2019-02-21 19:13
The tuple (host, port) is ("fe80::5054:01ff:fe04:3402%node4_client", 22) in The substring "node4_client" identifies the interface, which is needed for link local connections.

The function self._ensure_resolved() is called and resolves to
infos[0][4] = ("fe80::5054:01ff:fe04:3402", 22, something, 93), where 93 is the resolved scope id (see sin6_scope_id from struct sockaddr_in6 from man ipv6).

Afterwards the self.sock_connect() is called with address = infos[0][4].   In self.sock_connect() the function self._ensure_resolved() is called again. In the scope id is stripped from the tuple. The tuple (host, port) is now only ("fe80::5054:01ff:fe04:3402", 22) and therefore the scope id is lost.

I wrote this quick fix, which is not really suitable as a real solution for the problem:

lemoer@orange ~> diff /usr/lib/python3.7/asyncio/{.bak,}
--- /usr/lib/python3.7/asyncio/	2019-02-21 18:42:17.060122277 +0100
+++ /usr/lib/python3.7/asyncio/	2019-02-21 18:49:36.886866750 +0100
@@ -942,8 +942,8 @@
                             sock = None
                     if self._debug:
-                        logger.debug("connect %r to %r", sock, address)
-                    await self.sock_connect(sock, address)
+                        logger.debug("connect %r to %r", sock, (host, port))
+                    await self.sock_connect(sock, (host, port))
                 except OSError as exc:
                     if sock is not None:
msg336254 - (view) Author: Leonardo Mörlein (Leonardo Mörlein) Date: 2019-02-21 19:16
The generated error is:

OSError: [Errno 22] Invalid argument
msg336255 - (view) Author: Leonardo Mörlein (Leonardo Mörlein) Date: 2019-02-21 19:28
It seems to be a regression, as my python 3.6 version is not affected:

lemoer@orange ~> python3.6 --version
Python 3.6.8

My python 3.7 version is affected:

lemoer@orange ~> python3.7 --version
Python 3.7.2
msg336281 - (view) Author: twisteroid ambassador (twisteroid ambassador) * Date: 2019-02-22 06:26
Duplicate of issue35545, I believe.
msg336284 - (view) Author: Leonardo Mörlein (Leonardo Mörlein) Date: 2019-02-22 08:05
Oh, you are correct. So this can be closed.
Date User Action Args
2022-04-11 14:59:11adminsetgithub: 80250
2019-02-22 08:05:56Leonardo Mörleinsetstatus: open -> closed
stage: resolved
2019-02-22 08:05:17Leonardo Mörleinsetmessages: + msg336284
2019-02-22 06:26:04twisteroid ambassadorsetnosy: + twisteroid ambassador
messages: + msg336281
2019-02-21 19:28:28Leonardo Mörleinsetmessages: + msg336255
2019-02-21 19:16:05Leonardo Mörleinsetmessages: + msg336254
2019-02-21 19:13:47Leonardo Mörleincreate