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: Go routine inside Go routine not exiting normally ? #20793

Closed
zkynet opened this issue Jun 25, 2017 · 9 comments

Comments

Projects
None yet
6 participants
@zkynet
Copy link

commented Jun 25, 2017

Please answer these questions before submitting your issue. Thanks!

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

go version go1.8 darwin/amd64

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/anon/base/code/golang/"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/b8/3rkdjmp97bsbgsf5pn7xcwlw0000gn/T/go-build995600224=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

Introduced a 1 millisecond sleep timer into a goroutine before returning

https://play.golang.org/p/N5-mzj9Ywk

What did you expect to see?

Garbage collection.

What did you see instead?

No garbage collection.

Notes

There are two main functions in the go-playground exmaple..
runSpawner and runSpawner2

If you run spawner 1 before spawner 2 no garbage collection happens.
But if you reverse the order, spawner 2 child processes get garbage collected.

I don't know why this happens.. but it seems a sleep timer within a goroutine stops it ( and future processes ) from getting garbage collected ?

@davecheney

This comment has been minimized.

Copy link
Contributor

commented Jun 25, 2017

@zkynet

This comment has been minimized.

Copy link
Author

commented Jun 25, 2017

So you are telling me that if that infinite loop would be a process serving up a websocket any goroutines spawned before that loop would never get garbage collected ?

example: https://play.golang.org/p/JFDg1oTVcE

@davecheney

This comment has been minimized.

Copy link
Contributor

commented Jun 25, 2017

@mvdan

This comment has been minimized.

Copy link
Member

commented Jun 25, 2017

Perhaps related to #10958 - that issue is about loops that don't have any blocking points or function calls, which currently interfere with GC.

@zkynet

This comment has been minimized.

Copy link
Author

commented Jun 25, 2017

This code get's full memory return

https://play.golang.org/p/iJoD9YDIia

this does not

https://play.golang.org/p/U-CZ-TOWTA

It seems running goroutines within goroutines somehow does not work very well ? .. it seems the second level goroutines start stacking up and never exiting. Even if you tell them to return once finished.

Is there a reason for this :( ?

@zkynet zkynet changed the title time.Sleep breaking garbage collection ? Go routine inside Go routine not exiting normally ? Jun 25, 2017

@ALTree

This comment has been minimized.

Copy link
Member

commented Jun 25, 2017

No garbage collection.

How are you measuring this? This report lacks details.

This code get's full memory return

Again: how are you measuring "memory return" ? The two new examples you posted both crash and exit because they deadlock. How are you measuring memory consumption? And when? Where's the code that you use for memory consumption profiling?

@zkynet

This comment has been minimized.

Copy link
Author

commented Jun 25, 2017

@ALTree I've been watching the memory consumption of the running process both from the terminal and some GUI tools.

But whats more important is that I've just been wrong this whole time.

I've been assuming things are non-blocking when they aren't and my general lack of knowledge lead me to all the wrong conclusion !

Feel free to close this issue and burn it :(

@josharian josharian closed this Jun 25, 2017

@ALTree

This comment has been minimized.

Copy link
Member

commented Jun 25, 2017

No problem, thanks for checking.

As a general suggestion, if you are unsure about something it's better to bring it up as a question in one of the places we use for questions (see: Questions). The people there, then, will advise you and tell you to open an issue on the issue tracker if what you found is an actual bug.

@davecheney

This comment has been minimized.

Copy link
Contributor

commented Jun 25, 2017

@mikioh mikioh changed the title Go routine inside Go routine not exiting normally ? runtime: Go routine inside Go routine not exiting normally ? Aug 2, 2017

@golang golang locked and limited conversation to collaborators Aug 3, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.