Skip to content

asyncio.open_connection(local_addr=('localhost', port)) fails with TypeError: AF_INET address must be a pair (host, port) #86508

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

Closed
ecatmur mannequin opened this issue Nov 13, 2020 · 1 comment · Fixed by #100615
Assignees
Labels
3.10 only security fixes 3.11 only security fixes 3.12 only security fixes topic-asyncio type-bug An unexpected behavior, bug, or error

Comments

@ecatmur
Copy link
Mannequin

ecatmur mannequin commented Nov 13, 2020

BPO 42342
Nosy @asvetlov, @1st1, @ecatmur

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:

assignee = None
closed_at = None
created_at = <Date 2020-11-13.10:23:37.431>
labels = ['type-bug', '3.8', 'expert-asyncio']
title = "asyncio.open_connection(local_addr=('localhost', port)) fails with TypeError: AF_INET address must be a pair (host, port)"
updated_at = <Date 2020-11-13.10:23:37.431>
user = 'https://github.com/ecatmur'

bugs.python.org fields:

activity = <Date 2020-11-13.10:23:37.431>
actor = 'ecatmur2'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['asyncio']
creation = <Date 2020-11-13.10:23:37.431>
creator = 'ecatmur2'
dependencies = []
files = []
hgrepos = []
issue_num = 42342
keywords = []
message_count = 1.0
messages = ['380874']
nosy_count = 3.0
nosy_names = ['asvetlov', 'yselivanov', 'ecatmur2']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue42342'
versions = ['Python 3.8']

Linked PRs

@ecatmur
Copy link
Mannequin Author

ecatmur mannequin commented Nov 13, 2020

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 bpo-35302 - we should be filtering local addrinfos by family for valid combinations.

@ecatmur ecatmur mannequin added 3.8 (EOL) end of life topic-asyncio type-bug An unexpected behavior, bug, or error labels Nov 13, 2020
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@ezio-melotti ezio-melotti moved this to Todo in asyncio Jul 17, 2022
@kumaraditya303 kumaraditya303 added 3.11 only security fixes 3.10 only security fixes 3.12 only security fixes and removed 3.8 (EOL) end of life labels Dec 30, 2022
@kumaraditya303 kumaraditya303 self-assigned this Dec 30, 2022
@kumaraditya303 kumaraditya303 moved this from Todo to In Progress in asyncio Dec 30, 2022
kumaraditya303 added a commit that referenced this issue Jan 4, 2023
@github-project-automation github-project-automation bot moved this from In Progress to Done in asyncio Jan 4, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jan 4, 2023
…n `asyncio.open_connection` (pythonGH-100615)

(cherry picked from commit ba8dcdb)

Co-authored-by: Kumar Aditya <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jan 4, 2023
…n `asyncio.open_connection` (pythonGH-100615)

(cherry picked from commit ba8dcdb)

Co-authored-by: Kumar Aditya <[email protected]>
miss-islington added a commit that referenced this issue Jan 4, 2023
…ncio.open_connection` (GH-100615)

(cherry picked from commit ba8dcdb)

Co-authored-by: Kumar Aditya <[email protected]>
miss-islington added a commit that referenced this issue Jan 4, 2023
…ncio.open_connection` (GH-100615)

(cherry picked from commit ba8dcdb)

Co-authored-by: Kumar Aditya <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.10 only security fixes 3.11 only security fixes 3.12 only security fixes topic-asyncio type-bug An unexpected behavior, bug, or error
Projects
Status: Done
1 participant