mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
GH-86508: skip binding to local addresses of different family in asyncio.open_connection
(#100615)
This commit is contained in:
parent
a286caa937
commit
ba8dcdbcab
3 changed files with 50 additions and 2 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue