From fb441da4ae8e0679ef1169a519b474174a413ba6 Mon Sep 17 00:00:00 2001 From: Lin Lin Date: Wed, 3 Dec 2025 09:04:03 +0800 Subject: [PATCH] syscall: make LoadConnectEx not IPv4-specific on Windows Calls to Socket in LoadConnectEx always fail with the error "An address incompatible with the requested protocol was used" when IPv4 is disabled on Windows. We can work around this by detecting that specific error and retrying with an IPv6 socket. Fixes #29759 --- src/syscall/syscall_windows.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/syscall/syscall_windows.go b/src/syscall/syscall_windows.go index 3e63897b6bc3a3..045e58fe1989f2 100644 --- a/src/syscall/syscall_windows.go +++ b/src/syscall/syscall_windows.go @@ -14,6 +14,7 @@ import ( "internal/oserror" "internal/race" "internal/strconv" + strings "internal/stringslite" "sync" "unsafe" ) @@ -1097,10 +1098,16 @@ var connectExFunc struct { func LoadConnectEx() error { connectExFunc.once.Do(func() { - var s Handle - s, connectExFunc.err = Socket(AF_INET, SOCK_STREAM, IPPROTO_TCP) - if connectExFunc.err != nil { - return + s, err := Socket(AF_INET, SOCK_STREAM, IPPROTO_TCP) + if err != nil { + // This can occur when IPv4 is disabled. See https://go.dev/issue/29759. + if strings.Index(err.Error(), "address incompatible with the requested protocol was used") >= 0 { + s, err = Socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP) + } + connectExFunc.err = err + if err != nil { + return + } } defer CloseHandle(s) var n uint32