diff options
author | Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> | 2023-01-04 08:00:26 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-04 08:00:26 (GMT) |
commit | ba8dcdbcab5fd9989be6c9a51002394e782c463c (patch) | |
tree | 5b83b3e4cba8cbb1d6232b49b66aaf41f6177476 /Lib/asyncio/base_events.py | |
parent | a286caa937405f7415dcc095a7ad5097c4433246 (diff) | |
download | cpython-ba8dcdbcab5fd9989be6c9a51002394e782c463c.zip cpython-ba8dcdbcab5fd9989be6c9a51002394e782c463c.tar.gz cpython-ba8dcdbcab5fd9989be6c9a51002394e782c463c.tar.bz2 |
GH-86508: skip binding to local addresses of different family in `asyncio.open_connection` (#100615)
Diffstat (limited to 'Lib/asyncio/base_events.py')
-rw-r--r-- | Lib/asyncio/base_events.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py index f2f9375..cbabb43 100644 --- a/Lib/asyncio/base_events.py +++ b/Lib/asyncio/base_events.py @@ -961,7 +961,10 @@ class BaseEventLoop(events.AbstractEventLoop): sock = socket.socket(family=family, type=type_, proto=proto) sock.setblocking(False) if local_addr_infos is not None: - for _, _, _, _, laddr in local_addr_infos: + for lfamily, _, _, _, laddr in local_addr_infos: + # skip local addresses of different family + if lfamily != family: + continue try: sock.bind(laddr) break @@ -974,7 +977,10 @@ class BaseEventLoop(events.AbstractEventLoop): exc = OSError(exc.errno, msg) my_exceptions.append(exc) else: # all bind attempts failed - raise my_exceptions.pop() + if my_exceptions: + raise my_exceptions.pop() + else: + raise OSError(f"no matching local address with {family=} found") await self.sock_connect(sock, address) return sock except OSError as exc: |