-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Description
Go version
go version go1.22.4 windows/amd64
Output of go env
in your module/workspace:
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=C:\src\infra\infra\go\bin
set GOCACHE=C:\src\infra\infra\go\golang\gocache
set GOENV=C:\Users\philwo\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\src\infra\infra\go\golang\modcache
set GONOPROXY=*.googlesource.com,*.git.corp.google.com,google.com
set GONOSUMDB=*.googlesource.com,*.git.corp.google.com,google.com
set GOOS=windows
set GOPATH=C:\Users\philwo\go
set GOPRIVATE=*.googlesource.com,*.git.corp.google.com,google.com
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\src\infra\infra\go\golang\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=local
set GOTOOLDIR=C:\src\infra\infra\go\golang\go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.22.4
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOMOD=C:\src\infra\infra\go\src\infra\go.mod
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\src\temp\go-build1415248655=/tmp/go-build -gno-record-gcc-switches
What did you do?
I ran various tools that are part of Chromium's build tooling and are written in Go (reproxy, Siso), which have a mysterious startup overhead on my corporate Windows machine when I'm logged in via SSH, sometimes between 30s - 120s.
I traced it down to all of them depending on glog, which calls user.Current()
in its init function. user.Current()
on corporate Windows (joined to a domain) makes a network call to figure out the display name of the current user, which is part of the user.User
struct returned by the function.
None of the callers that I inspected actually need the display name, they only wanted to know the username and/or the home directory of the user. However, there is no lightweight API available in the Go standard library that would allow callers to only get the username without the display name.
Here's a minimal repro example: https://go.dev/play/p/ODg6zPl1M1p
I found some other reports about this in the past as well:
- https://go.dev/issue/21867 would like
user.Current()
on Windows to stop making these network calls, because they don't work inside a container with Nano Server. - https://go.dev/issue/5298 reported a similar issue, but the fix only helped Windows computers that aren't part of a domain
- Slow startup on Windows gokcehan/lf#1097 (comment) -
- Delve slow startup (60+ seconds in some cases) causes debugging to timeout when running in IntelliJ Idea. go-delve/delve#2072 - "Delve attempts to find out the home directory of the current user. This is done using user.Current() function in os/user package, which takes more than 60 seconds to return."
- Opa cli slow on Windows 10 open-policy-agent/opa#4646 (comment) - "We've located another user.Current() call in the transitive deps of badger"
- Docker Desktop on Windows: 'docker context inspect' is very slow docker/cli#2420 - "I took a trace (available upon request) and noticed that the majority of time is spent waiting on results from NetUserGetInfo Windows API."
- [libbeat] Windows service timeouts elastic/beats#31810 (comment) - "We have a reliable means of reproducing. If the Windows hosts has been hardened by disabling the "TCP/IP NetBIOS Helper" service then the lookup takes up to 60s to timeout."
- The kubectl commands become significant slower when using kubelogin Azure/kubelogin#102 (comment) - "Actually it appears to be klog, not Cobra. In its initialization code it's calling user.Current(), which ends up hitting that endpoint on Windows."
What did you see happen?
The provided example takes ~500ms in the best case on corporate Windows for me, but between 30s - 120s when anything goes wrong with the network call to Active Directory triggered by user.Current()
's call to TranslateAccountName or NetUserGetInfo, which is unfortunately regularly the case (and currently for yet unknown reasons always when logged in to the machine via SSH instead of Remote Desktop).
Here's an example where I added timing measurements to the calls in the code:
> .\getuser.exe
syscall.NetGetJoinInformation() took 1.161ms
syscall.TranslateAccountName() took 1m5.5853054s
syscall.NetUserGetInfo() took 22.1981487s
In total, user.Current() took 1m27.788102s
What did you expect to see?
user.Current()
should returns within single-digit milliseconds, like on macOS and Linux.