From 0487710ceddbb7ff40f91cd258942429e79c4031 Mon Sep 17 00:00:00 2001 From: Marcin Zawiejski Date: Mon, 18 Sep 2023 14:32:57 +0200 Subject: [PATCH 1/3] windows gc fix --- tools/network/dnssec/config_windows.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tools/network/dnssec/config_windows.go b/tools/network/dnssec/config_windows.go index 36c0aaf377..5da4049cdc 100644 --- a/tools/network/dnssec/config_windows.go +++ b/tools/network/dnssec/config_windows.go @@ -21,7 +21,6 @@ package dnssec import ( "fmt" - "runtime/debug" "time" "unsafe" @@ -94,25 +93,30 @@ type fixedInfoWithOverlay struct { // See GetNetworkParams for details: // https://docs.microsoft.com/en-us/windows/win32/api/iphlpapi/nf-iphlpapi-getnetworkparams func SystemConfig() (servers []ResolverAddress, timeout time.Duration, err error) { - // disable GC to prevent fi collection earlier than lookups in fi completed - pct := debug.SetGCPercent(-1) - defer debug.SetGCPercent(pct) + ulSize := uint32(unsafe.Sizeof(fixedInfoWithOverlay{})) + + buf, err := windows.LocalAlloc(windows.LMEM_FIXED, ulSize) + if err != nil { + err = fmt.Errorf("GetNetworkParams failed to allocate %d bytes of memory for fixedInfoWithOverlay", ulSize) + } + + defer windows.LocalFree(windows.Handle(buf)) - var fi fixedInfoWithOverlay - var ulSize uint32 = uint32(unsafe.Sizeof(fi)) ret, _, _ := networkParamsProc.Call( - uintptr(unsafe.Pointer(&fi)), + buf, uintptr(unsafe.Pointer(&ulSize)), ) if ret != 0 { if windows.Errno(ret) == windows.ERROR_BUFFER_OVERFLOW { - err = fmt.Errorf("GetNetworkParams requested %d bytes of memory, max supported is %d. Error code is %x", ulSize, unsafe.Sizeof(fi), ret) + err = fmt.Errorf("GetNetworkParams requested %d bytes of memory, max supported is %d. Error code is %x", ulSize, unsafe.Sizeof(fixedInfoWithOverlay{}), ret) return } err = fmt.Errorf("GetNetworkParams failed with code is %x", ret) return } + fi := (*fixedInfoWithOverlay)(unsafe.Pointer(buf)) + var p *ipAddrString = &fi.DnsServerList for { ip := make([]byte, ip_size) From 14c9d8e2f0c32176a4383fc553bc5d10ec6223d2 Mon Sep 17 00:00:00 2001 From: Marcin Zawiejski Date: Mon, 18 Sep 2023 18:00:01 +0200 Subject: [PATCH 2/3] Update tools/network/dnssec/config_windows.go Co-authored-by: Pavel Zbitskiy <65323360+algorandskiy@users.noreply.github.com> --- tools/network/dnssec/config_windows.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/network/dnssec/config_windows.go b/tools/network/dnssec/config_windows.go index 5da4049cdc..58098ef6a4 100644 --- a/tools/network/dnssec/config_windows.go +++ b/tools/network/dnssec/config_windows.go @@ -95,7 +95,7 @@ type fixedInfoWithOverlay struct { func SystemConfig() (servers []ResolverAddress, timeout time.Duration, err error) { ulSize := uint32(unsafe.Sizeof(fixedInfoWithOverlay{})) - buf, err := windows.LocalAlloc(windows.LMEM_FIXED, ulSize) + buf, err := windows.LocalAlloc(windows.LMEM_FIXED | windows.LMEM_ZEROINIT, ulSize) if err != nil { err = fmt.Errorf("GetNetworkParams failed to allocate %d bytes of memory for fixedInfoWithOverlay", ulSize) } From 8a1eae131f7ada526a82dfa7f5426add245d2bd6 Mon Sep 17 00:00:00 2001 From: Pavel Zbitskiy <65323360+algorandskiy@users.noreply.github.com> Date: Mon, 18 Sep 2023 12:29:22 -0400 Subject: [PATCH 3/3] Update tools/network/dnssec/config_windows.go --- tools/network/dnssec/config_windows.go | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/network/dnssec/config_windows.go b/tools/network/dnssec/config_windows.go index 58098ef6a4..f41d6b6be7 100644 --- a/tools/network/dnssec/config_windows.go +++ b/tools/network/dnssec/config_windows.go @@ -98,6 +98,7 @@ func SystemConfig() (servers []ResolverAddress, timeout time.Duration, err error buf, err := windows.LocalAlloc(windows.LMEM_FIXED | windows.LMEM_ZEROINIT, ulSize) if err != nil { err = fmt.Errorf("GetNetworkParams failed to allocate %d bytes of memory for fixedInfoWithOverlay", ulSize) + return } defer windows.LocalFree(windows.Handle(buf))