[New-bugs-announce] [issue42342] asyncio.open_connection(local_addr=('localhost', port)) fails with TypeError: AF_INET address must be a pair (host, port)

Ed Catmur report at bugs.python.org
Fri Nov 13 05:23:37 EST 2020


New submission from Ed Catmur <ed at catmur.uk>:

Context: CentOS 7.8.2003, Python 3.8 from SCL. localhost has IPv4 and IPv6 bindings, IPv6 first:
$ python -c "import socket;print(socket.getaddrinfo('localhost',0,type=socket.SOCK_STREAM))"
[(<AddressFamily.AF_INET6: 10>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('::1', 0, 0, 0)), (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('127.0.0.1', 0))]

import asyncio
async def main():
    await asyncio.open_connection('localhost', 9990, local_addr=('localhost', 9991))
asyncio.run(main())

Traceback (most recent call last):
  File "async.py", line 4, in <module>
    asyncio.run(main())
  File "/opt/rh/rh-python38/root/usr/lib64/python3.8/asyncio/runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "/opt/rh/rh-python38/root/usr/lib64/python3.8/asyncio/base_events.py", line 608, in run_until_complete
    return future.result()
  File "async.py", line 3, in main
    await asyncio.open_connection('10.10.10.10', 9990, local_addr=('localhost', 9991))
  File "/opt/rh/rh-python38/root/usr/lib64/python3.8/asyncio/streams.py", line 52, in open_connection
    transport, _ = await loop.create_connection(
  File "/opt/rh/rh-python38/root/usr/lib64/python3.8/asyncio/base_events.py", line 1002, in create_connection
    sock = await self._connect_sock(
  File "/opt/rh/rh-python38/root/usr/lib64/python3.8/asyncio/base_events.py", line 904, in _connect_sock
    sock.bind(laddr)
TypeError: AF_INET address must be a pair (host, port)

It looks like this has a similar root cause to issue 35302 - we should be filtering local addrinfos by family for valid combinations.

----------
components: asyncio
messages: 380874
nosy: asvetlov, ecatmur2, yselivanov
priority: normal
severity: normal
status: open
title: asyncio.open_connection(local_addr=('localhost', port)) fails with TypeError: AF_INET address must be a pair (host, port)
type: behavior
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42342>
_______________________________________


More information about the New-bugs-announce mailing list