Skip to content

Commit 9396ef1

Browse files
[PR #10542/e1d2d77c backport][3.11] only use AI_ADDRCONFIG when supported by getaddrinfo (#10578)
1 parent 4005080 commit 9396ef1

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

CHANGES/10542.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed DNS resolution on platforms that don't support ``socket.AI_ADDRCONFIG`` -- by :user:`maxbachmann`.

aiohttp/resolver.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
_NUMERIC_SOCKET_FLAGS = socket.AI_NUMERICHOST | socket.AI_NUMERICSERV
2020
_NAME_SOCKET_FLAGS = socket.NI_NUMERICHOST | socket.NI_NUMERICSERV
21+
_AI_ADDRCONFIG = socket.AI_ADDRCONFIG
22+
if hasattr(socket, "AI_MASK"):
23+
_AI_ADDRCONFIG &= socket.AI_MASK
2124

2225

2326
class ThreadedResolver(AbstractResolver):
@@ -38,7 +41,7 @@ async def resolve(
3841
port,
3942
type=socket.SOCK_STREAM,
4043
family=family,
41-
flags=socket.AI_ADDRCONFIG,
44+
flags=_AI_ADDRCONFIG,
4245
)
4346

4447
hosts: List[ResolveResult] = []
@@ -105,7 +108,7 @@ async def resolve(
105108
port=port,
106109
type=socket.SOCK_STREAM,
107110
family=family,
108-
flags=socket.AI_ADDRCONFIG,
111+
flags=_AI_ADDRCONFIG,
109112
)
110113
except aiodns.error.DNSError as exc:
111114
msg = exc.args[1] if len(exc.args) >= 1 else "DNS lookup failed"

0 commit comments

Comments
 (0)