Skip to content

Commit ec9b502

Browse files
committed
bpo-27929: resolve names only for AF_INET/AF_INET6 with asyncio
For other families, it may not make sense to resolve names. For example, with AF_BLUETOOTH, there is no name resolution and attempting to do so will trigger a "ai_family not supported". The bug report contains an example: ```python import asyncio import socket sock = socket.socket(family=socket.AF_BLUETOOTH, type=socket.SOCK_STREAM, proto=socket.BTPROTO_RFCOMM) sock.setblocking(False) addr = "00:12:34:56:78:99" loop = asyncio.get_event_loop() loop.run_until_complete(loop.sock_connect(sock, (addr, 1))) ``` https://bugs.python.org/issue27929
1 parent e8e737b commit ec9b502

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

Lib/asyncio/selector_events.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,8 @@ async def sock_connect(self, sock, address):
620620
if self._debug and sock.gettimeout() != 0:
621621
raise ValueError("the socket must be non-blocking")
622622

623-
if not hasattr(socket, 'AF_UNIX') or sock.family != socket.AF_UNIX:
623+
if sock.family == socket.AF_INET or (
624+
base_events._HAS_IPv6 and sock.family == socket.AF_INET6):
624625
resolved = await self._ensure_resolved(
625626
address, family=sock.family, type=sock.type, proto=sock.proto,
626627
loop=self,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix :func:`asyncio.sock_connect` to only resolve names for ``AF_INET`` or
2+
``AF_INET6`` families. Resolution may not make sense for other families,
3+
like ``AF_BLUETOOTH`` and ``AF_UNIX``.

0 commit comments

Comments
 (0)