[Python-checkins] bpo-27929: resolve names only for AF_INET/AF_INET6 with asyncio (GH-32131)

asvetlov webhook-mailer at python.org
Mon Mar 28 17:50:34 EDT 2022


https://github.com/python/cpython/commit/5c30388f3c586ba2f33e349e22e5949cb92de621
commit: 5c30388f3c586ba2f33e349e22e5949cb92de621
branch: main
author: Vincent Bernat <vincent at bernat.ch>
committer: asvetlov <andrew.svetlov at gmail.com>
date: 2022-03-29T00:50:26+03:00
summary:

bpo-27929: resolve names only for AF_INET/AF_INET6 with asyncio (GH-32131)

Co-authored-by: Andrew Svetlov <andrew.svetlov at gmail.com>

files:
A Misc/NEWS.d/next/Library/2022-03-28-13-35-50.bpo-27929.j5mAmV.rst
M Lib/asyncio/selector_events.py

diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py
index 33ebc4b27808c..e99a50395e7cb 100644
--- a/Lib/asyncio/selector_events.py
+++ b/Lib/asyncio/selector_events.py
@@ -620,7 +620,8 @@ async def sock_connect(self, sock, address):
         if self._debug and sock.gettimeout() != 0:
             raise ValueError("the socket must be non-blocking")
 
-        if not hasattr(socket, 'AF_UNIX') or sock.family != socket.AF_UNIX:
+        if sock.family == socket.AF_INET or (
+                base_events._HAS_IPv6 and sock.family == socket.AF_INET6):
             resolved = await self._ensure_resolved(
                 address, family=sock.family, type=sock.type, proto=sock.proto,
                 loop=self,
diff --git a/Misc/NEWS.d/next/Library/2022-03-28-13-35-50.bpo-27929.j5mAmV.rst b/Misc/NEWS.d/next/Library/2022-03-28-13-35-50.bpo-27929.j5mAmV.rst
new file mode 100644
index 0000000000000..4c80a10bc5684
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-03-28-13-35-50.bpo-27929.j5mAmV.rst
@@ -0,0 +1,3 @@
+Fix :meth:`asyncio.loop.sock_connect` to only resolve names for :const:`socket.AF_INET` or
+:const:`socket.AF_INET6` families. Resolution may not make sense for other families,
+like :const:`socket.AF_BLUETOOTH` and :const:`socket.AF_UNIX`.



More information about the Python-checkins mailing list