summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio/base_events.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-01-04 08:28:00 (GMT)
committerGitHub <noreply@github.com>2023-01-04 08:28:00 (GMT)
commitad40764f5b1e0a11a8b4a30b7ce2dacc20fda12f (patch)
tree57c7de9759b88e5ef5a53c5681ecd7da2c466917 /Lib/asyncio/base_events.py
parentd8073ee6f318773c2600f1e486ccab2504a03cdd (diff)
downloadcpython-ad40764f5b1e0a11a8b4a30b7ce2dacc20fda12f.zip
cpython-ad40764f5b1e0a11a8b4a30b7ce2dacc20fda12f.tar.gz
cpython-ad40764f5b1e0a11a8b4a30b7ce2dacc20fda12f.tar.bz2
GH-86508: skip binding to local addresses of different family in `asyncio.open_connection` (GH-100615)
(cherry picked from commit ba8dcdbcab5fd9989be6c9a51002394e782c463c) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Diffstat (limited to 'Lib/asyncio/base_events.py')
-rw-r--r--Lib/asyncio/base_events.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index 8f3e1b3..4692f95 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -950,7 +950,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
@@ -963,7 +966,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: