From 9deb2cb12d3975f64bd5b869deb2ce07e4b64630 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 20 Jul 2026 22:03:44 +0300 Subject: [PATCH 1/2] gh-154291: Fix socket.has_dualstack_ipv6() on DragonFly On DragonFly BSD setsockopt(IPPROTO_IPV6, IPV6_V6ONLY, 0) succeeds without actually clearing the flag, so has_dualstack_ipv6() wrongly returned True. Verify with getsockopt() that IPV6_V6ONLY was cleared. Co-Authored-By: Claude Opus 4.8 (1M context) --- Lib/socket.py | 4 +++- .../Library/2026-07-20-22-03-44.gh-issue-154291.Mi5HeQ.rst | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2026-07-20-22-03-44.gh-issue-154291.Mi5HeQ.rst diff --git a/Lib/socket.py b/Lib/socket.py index 03c3fe88f15cfe..2a4f875f76b069 100644 --- a/Lib/socket.py +++ b/Lib/socket.py @@ -900,7 +900,9 @@ def has_dualstack_ipv6(): try: with socket(AF_INET6, SOCK_STREAM) as sock: sock.setsockopt(IPPROTO_IPV6, IPV6_V6ONLY, 0) - return True + # On some platforms (e.g. DragonFly BSD) setting IPV6_V6ONLY to 0 + # silently has no effect, so check that it was actually cleared. + return sock.getsockopt(IPPROTO_IPV6, IPV6_V6ONLY) == 0 except error: return False diff --git a/Misc/NEWS.d/next/Library/2026-07-20-22-03-44.gh-issue-154291.Mi5HeQ.rst b/Misc/NEWS.d/next/Library/2026-07-20-22-03-44.gh-issue-154291.Mi5HeQ.rst new file mode 100644 index 00000000000000..649e97e988b966 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-07-20-22-03-44.gh-issue-154291.Mi5HeQ.rst @@ -0,0 +1,3 @@ +Fix :func:`socket.has_dualstack_ipv6` to return ``False`` on platforms such as +DragonFly BSD where setting :data:`~socket.IPV6_V6ONLY` to 0 silently has no +effect. From 2d1b75ecd0a4c7d837faf4b8505e4eba958054b8 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 20 Jul 2026 22:25:08 +0300 Subject: [PATCH 2/2] Use a literal for the undocumented IPV6_V6ONLY constant in the NEWS entry Co-Authored-By: Claude Opus 4.8 (1M context) --- .../next/Library/2026-07-20-22-03-44.gh-issue-154291.Mi5HeQ.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2026-07-20-22-03-44.gh-issue-154291.Mi5HeQ.rst b/Misc/NEWS.d/next/Library/2026-07-20-22-03-44.gh-issue-154291.Mi5HeQ.rst index 649e97e988b966..d962f8987ad491 100644 --- a/Misc/NEWS.d/next/Library/2026-07-20-22-03-44.gh-issue-154291.Mi5HeQ.rst +++ b/Misc/NEWS.d/next/Library/2026-07-20-22-03-44.gh-issue-154291.Mi5HeQ.rst @@ -1,3 +1,3 @@ Fix :func:`socket.has_dualstack_ipv6` to return ``False`` on platforms such as -DragonFly BSD where setting :data:`~socket.IPV6_V6ONLY` to 0 silently has no +DragonFly BSD where setting ``IPV6_V6ONLY`` to 0 silently has no effect.