Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: created thread still not exit while goroutine has exit for a long time #37772

Closed
linqh1 opened this issue Mar 10, 2020 · 3 comments
Closed

Comments

@linqh1
Copy link

linqh1 commented Mar 10, 2020

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

$ go version
go version go1.11.10 linux/amd64

Does this issue reproduce with the latest release?

yes, still in version go version go1.14 linux/amd64

but less threadcreate

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
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-build006288910=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I open 2 goroutines and do http request in loop, last 120 seconds

mock-echo-server.go: https://play.golang.org/p/n8oe5bLP3SS

build and run (listen on 127.0.0.1:9876)
./mock-echo-server

http-client.go: https://play.golang.org/p/99AXCkBZp8q

build and run (do http request(127.0.0.1:9876) for 120 seconds and sleep, pprof listen on 127.0.0.1:11111)
./http-client

What did you expect to see?

1 hour gone, the threadcreate number should decrease to normal

What did you see instead?

threadcreate number is still keep in maxium(70+ for go 1.11.10, 20+ for go 1.14)

image for prrof, since http request has been stop for 1 hour

go 1.11
image

go 1.14
image

I wonder why http-client.go still keep those idle threads while most of goroutine has exit for a long time.

Is there a way to stop those idle threads?

@toothrot toothrot changed the title created thread still not exit while goroutine has exit for a long time runtime: created thread still not exit while goroutine has exit for a long time Mar 10, 2020
@toothrot
Copy link
Contributor

From the docs:

threadcreate - stack traces that led to the creation of new OS threads

Is this not a cumulative number?

It's not clear to me that this is a bug. See https://golang.org/wiki/Questions for help debugging Go. I will close this issue, but please comment if you feel I am incorrect.

@linqh1
Copy link
Author

linqh1 commented Mar 11, 2020

From the docs:

threadcreate - stack traces that led to the creation of new OS threads

Is this not a cumulative number?

It's not clear to me that this is a bug. See https://golang.org/wiki/Questions for help debugging Go. I will close this issue, but please comment if you feel I am incorrect.

I check the thread count of http-client process, it does keep 69 threads alive
cat /proc/210686/status | grep Threads
Threads: 69

@ianlancetaylor
Copy link
Contributor

Threads created by the Go runtime do not normally exit.

@golang golang locked and limited conversation to collaborators Mar 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants