From ab6ab507fcbb0bfea8337e8dd3d10251175c52ba Mon Sep 17 00:00:00 2001 From: James Tucker Date: Fri, 26 Jul 2024 14:10:57 -0700 Subject: [PATCH] internal/poll: disable SIO_UDP_NETRESET on Windows Windows UDP sockets have novel behavior in response to ICMP, where by default RecvFrom will receive a read error as a result of an incoming ICMP packet. This behavior is not portable or consistent with behavior on other platforms, so for consistency it is disabled here. This is similar to, but a different case from the prior change 3114bd6 / https://golang.org/issue/5834 that disabled one of the two flags influencing behavior in response to the reception of related ICMP. Updates #5834 Updates #68614 --- src/internal/poll/fd_windows.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/internal/poll/fd_windows.go b/src/internal/poll/fd_windows.go index 5eefeb90f19..ee772d3c41e 100644 --- a/src/internal/poll/fd_windows.go +++ b/src/internal/poll/fd_windows.go @@ -337,8 +337,8 @@ func (fd *FD) Init(net string, pollable bool) (string, error) { fd.skipSyncNotif = true } } - // Disable SIO_UDP_CONNRESET behavior. - // http://support.microsoft.com/kb/263823 + // Disable SIO_UDP_CONNRESET and SIO_UDP_NETRESET behavior. + // http://support.microsoft.com/kb/263823 / https://golang.org/issue/68614 switch net { case "udp", "udp4", "udp6": ret := uint32(0) @@ -348,6 +348,14 @@ func (fd *FD) Init(net string, pollable bool) (string, error) { if err != nil { return "wsaioctl", err } + + ret := uint32(0) + flag := uint32(0) + size := uint32(unsafe.Sizeof(flag)) + err := syscall.WSAIoctl(fd.Sysfd, syscall.SIO_UDP_NETRESET, (*byte)(unsafe.Pointer(&flag)), size, nil, 0, &ret, nil, 0) + if err != nil { + return "wsaioctl", err + } } fd.rop.mode = 'r' fd.wop.mode = 'w'