-
Notifications
You must be signed in to change notification settings - Fork 18k
runtime: Stack output is inconsistent with NumGoroutine output #11706
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
Comments
Not sure whether we should change the code or simply document it. |
Documenting would suffice for Go 1.5{.x}, but for Go 1.6 it would be nice to be able to get both, number of goroutines started by the system and number of goroutines started by myself. |
Will think more but it seems to me right now that runtime.Stack should just show system goroutines when you ask for all. We omit them from panic crashes to avoid cluttering crash output in simple programs, but if you're asking for 'all goroutines' it seems like probably you should get them all. Either that or it should never show them, and whichever it is, NumGoroutines should match. |
CL https://golang.org/cl/18343 mentions this issue. |
CL https://golang.org/cl/18432 mentions this issue. |
…utines [Repeat of CL 18343 with build fixes.] Before, NumGoroutine counted system goroutines and Stack (usually) didn't show them, which was inconsistent and confusing. To resolve which way they should be consistent, it seems like package main import "runtime" func main() { println(runtime.NumGoroutine()) } should print 1 regardless of internal runtime details. Make it so. Fixes #11706. Change-Id: If26749fec06aa0ff84311f7941b88d140552e81d Reviewed-on: https://go-review.googlesource.com/18432 Reviewed-by: Austin Clements <austin@google.com> Run-TryBot: Russ Cox <rsc@golang.org>
While trying to detect goroutines leaks from my program I noticed that runtime.NumGoroutine reports much higher number of goroutines (5) than reported by runtime.Stack (1).
After some poking around I figured that there are, indeed, some system routines running in the background.
Here is the repro: http://play.golang.org/p/WowC44lsh9
A few notes:
So this looks like runtime.NumGoroutine() should also depend on this environment variable to stay consistent (outputting only user-created goroutines is a feature and is very welcome).
The text was updated successfully, but these errors were encountered: