Skip to content

os/user: user.Current() too slow on Windows #68312

@philwo

Description

@philwo

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:

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions