From d91b0b3675ff486635e271fc6616b08f6edc0553 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Wed, 12 Mar 2025 12:41:09 +0100 Subject: [PATCH 1/6] only use `AI_ADDRCONFIG` when supported by getaddrinfo E.g. the fallback implementation for getaddrinfo in CPython doesn't support it and currently fails with a bad flags error --- aiohttp/resolver.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/aiohttp/resolver.py b/aiohttp/resolver.py index 9528cfe48da..df29960a97b 100644 --- a/aiohttp/resolver.py +++ b/aiohttp/resolver.py @@ -18,7 +18,9 @@ _NUMERIC_SOCKET_FLAGS = socket.AI_NUMERICHOST | socket.AI_NUMERICSERV _NAME_SOCKET_FLAGS = socket.NI_NUMERICHOST | socket.NI_NUMERICSERV - +_AI_ADDRCONFIG = socket.AI_ADDRCONFIG +if hasattr(socket, "AI_MASK"): + _AI_ADDRCONFIG &= socket.AI_MASK class ThreadedResolver(AbstractResolver): """Threaded resolver. @@ -38,7 +40,7 @@ async def resolve( port, type=socket.SOCK_STREAM, family=family, - flags=socket.AI_ADDRCONFIG, + flags=_AI_ADDRCONFIG, ) hosts: List[ResolveResult] = [] @@ -96,7 +98,7 @@ async def resolve( port=port, type=socket.SOCK_STREAM, family=family, - flags=socket.AI_ADDRCONFIG, + flags=_AI_ADDRCONFIG, ) except aiodns.error.DNSError as exc: msg = exc.args[1] if len(exc.args) >= 1 else "DNS lookup failed" From ade86836e60dc8f3342d5ff347c246bf5c5bfde3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 12 Mar 2025 11:49:47 +0000 Subject: [PATCH 2/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- aiohttp/resolver.py | 1 + 1 file changed, 1 insertion(+) diff --git a/aiohttp/resolver.py b/aiohttp/resolver.py index df29960a97b..d99970f3952 100644 --- a/aiohttp/resolver.py +++ b/aiohttp/resolver.py @@ -22,6 +22,7 @@ if hasattr(socket, "AI_MASK"): _AI_ADDRCONFIG &= socket.AI_MASK + class ThreadedResolver(AbstractResolver): """Threaded resolver. From 0146c30b3636066d1ff95a1ddab9807e19afdd4a Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 16 Mar 2025 23:23:32 +0100 Subject: [PATCH 3/6] add changelog --- CHANGES/10542.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 CHANGES/10542.bugfix diff --git a/CHANGES/10542.bugfix b/CHANGES/10542.bugfix new file mode 100644 index 00000000000..bbc49daf91e --- /dev/null +++ b/CHANGES/10542.bugfix @@ -0,0 +1 @@ +Fixed DNS resolution on platforms that don't support `AI_ADDRCONFIG` \ No newline at end of file From b0bbdaf4472f6d88321a6c5553d8baf1ee75d194 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 16 Mar 2025 22:24:10 +0000 Subject: [PATCH 4/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- CHANGES/10542.bugfix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES/10542.bugfix b/CHANGES/10542.bugfix index bbc49daf91e..fff18f6da00 100644 --- a/CHANGES/10542.bugfix +++ b/CHANGES/10542.bugfix @@ -1 +1 @@ -Fixed DNS resolution on platforms that don't support `AI_ADDRCONFIG` \ No newline at end of file +Fixed DNS resolution on platforms that don't support `AI_ADDRCONFIG` From c4b35ad76a11b4545ff25933164ab888ea50a304 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 16 Mar 2025 12:28:01 -1000 Subject: [PATCH 5/6] Update CHANGES/10542.bugfix --- CHANGES/10542.bugfix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES/10542.bugfix b/CHANGES/10542.bugfix index fff18f6da00..85df29f9d0e 100644 --- a/CHANGES/10542.bugfix +++ b/CHANGES/10542.bugfix @@ -1 +1 @@ -Fixed DNS resolution on platforms that don't support `AI_ADDRCONFIG` +Fixed DNS resolution on platforms that don't support `AI_ADDRCONFIG` -- by :user:`maxbachmann`. From 7d7d6b8008f221ea83ebea9863d7e21609038ef9 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 16 Mar 2025 12:28:32 -1000 Subject: [PATCH 6/6] Update CHANGES/10542.bugfix --- CHANGES/10542.bugfix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES/10542.bugfix b/CHANGES/10542.bugfix index 85df29f9d0e..fc3192308ad 100644 --- a/CHANGES/10542.bugfix +++ b/CHANGES/10542.bugfix @@ -1 +1 @@ -Fixed DNS resolution on platforms that don't support `AI_ADDRCONFIG` -- by :user:`maxbachmann`. +Fixed DNS resolution on platforms that don't support ``socket.AI_ADDRCONFIG`` -- by :user:`maxbachmann`.