Skip to content

Commit e1d2d77

Browse files
maxbachmannpre-commit-ci[bot]bdraco
authored
only use AI_ADDRCONFIG when supported by getaddrinfo (#10542)
The fallback implementation for getaddrinfo in CPython doesn't support `AI_ADDRCONFIG` and currently fails with a bad flags error. This changes the implementation to only set the flag if it's part of `AI_MASK`. Since `AI_MASK` isn't necessarily available either this has to be checked first. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: J. Nick Koston <[email protected]>
1 parent a59e74b commit e1d2d77

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] = []
@@ -96,7 +99,7 @@ async def resolve(
9699
port=port,
97100
type=socket.SOCK_STREAM,
98101
family=family,
99-
flags=socket.AI_ADDRCONFIG,
102+
flags=_AI_ADDRCONFIG,
100103
)
101104
except aiodns.error.DNSError as exc:
102105
msg = exc.args[1] if len(exc.args) >= 1 else "DNS lookup failed"

0 commit comments

Comments
 (0)