go: syscall: Setgroups may hang in go 1.16+ when not using cgo

What version of Go are you using (go version)?

$ go version
go version go1.16 linux/amd64

Does this issue reproduce with the latest release?

Yes, this problem will also exist in go 1.17.5, but not exist in go 1.15.x.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/demo/.cache/go-build"
GOENV="/home/demo/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/demo/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/demo/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/demo/golang-setgroups-hang/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3393189053=/tmp/go-build -gno-record-gcc-switches"

What did you do?

See https://github.com/weixiao-huang/golang-setgroups-hang

What did you expect to see?

client --key-path /.launch/key --server=localhost:2222 should not hang while compiled by golang 1.16.x and 1.17.x

What did you see instead?

client --key-path /.launch/key --server=localhost:2222 will hang while compiled by golang 1.16.x and 1.17.x

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 35 (26 by maintainers)

Commits related to this issue

Most upvoted comments

I think we do want something like the patch in https://github.com/golang/go/issues/50113#issuecomment-1014191407. The ability for a blocking system call anywhere in the program to block execution is AllThreadsSyscall is a quite painful limitation, particularly since most users won’t have the full-program awareness to know if there program might ever execute a blocking system call.

(Some system calls may not even be expected to block indefinitely, but expect to be woken by an action on another thread. But since we have stopped the world, that action never occurs and this thread remains blocked forever, causing a deadlock).

cc @aclements