From e93f439ac4160baf9992f059d2bfb511e23f63c9 Mon Sep 17 00:00:00 2001 From: qmuntal Date: Tue, 23 Sep 2025 10:46:46 +0200 Subject: [PATCH] runtime/cgo: retry when CreateThread fails with ERROR_ACCESS_DENIED _cgo_beginthread used to retry _beginthread only when it failed with EACCESS, but CL 651995 switched to CreateThread and incorrectly mapped EACCESS to ERROR_NOT_ENOUGH_MEMORY. The correct mapping is ERROR_ACCESS_DENIED. Fixes #72814 Fixes #75381 Change-Id: I8ba060114aae4e8249576f11a21eff613caa8001 Reviewed-on: https://go-review.googlesource.com/c/go/+/706075 Reviewed-by: Michael Pratt LUCI-TryBot-Result: Go LUCI Reviewed-by: Michael Knyszek --- src/runtime/cgo/gcc_libinit_windows.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/cgo/gcc_libinit_windows.c b/src/runtime/cgo/gcc_libinit_windows.c index 83fc874348..9275185d6e 100644 --- a/src/runtime/cgo/gcc_libinit_windows.c +++ b/src/runtime/cgo/gcc_libinit_windows.c @@ -145,7 +145,7 @@ void _cgo_beginthread(unsigned long (__stdcall *func)(void*), void* arg) { for (tries = 0; tries < 20; tries++) { thandle = CreateThread(NULL, 0, func, arg, 0, NULL); - if (thandle == 0 && GetLastError() == ERROR_NOT_ENOUGH_MEMORY) { + if (thandle == 0 && GetLastError() == ERROR_ACCESS_DENIED) { // "Insufficient resources", try again in a bit. // // Note that the first Sleep(0) is a yield.