-
Notifications
You must be signed in to change notification settings - Fork 18k
runtime/trace: using cgo introduces goroutine with empty stack #61037
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
I have noticed this as well. From my investigation, this appears to be an extra goroutine created for cgo programs in anticipation of C-to-Go calls. It's created here in |
/cc @golang/runtime |
I believe that @nsrip-dd is correct, this is the G from oneNewExtraM, which will be used when executing cgo callbacks that come from a non-Go thread. This is perhaps an unfortunate internal detail to expose, but I'm not sure we can/should change the trace output? In theory I suppose it would make more sense to delay the GoCreate until a cgo callback actually occurs, but should we do that on every callback that reuses the same G or only the first call? |
@nsrip-dd is exactly right. I think it needs to operate this way because of the existing requirements around goroutine states. The first thing such a goroutine ever does is, IIRC, emit a It is a little bit weird that this is treated as "the goroutine has been in a syscall the whole time." That aligns with how the runtime views the goroutine for sure, but not necessarily with how these goroutines behave from a user's perspective. We could, for instance, just pretend the goroutine is created and destroyed on each C->Go call (and return). The I imagine the reason this wasn't modeled this way originally is because it's a bit more complex. The |
I believe this might be fixed in the new tracer. The tracer now models this extra M goroutine as being created and destroyed, and I don't immediately see how a dead goroutine would ever end up in the trace now. (We try to 'suspend' every goroutine but it might just be dead, in which case we'll do nothing.) Closing optimistically. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you see?
The produced trace contains the following two events:
The EvStack for stack 3 contains a single frame, with all values set to zero.
The goroutine seems to be so special that its stack doesn't get printed when sending SIGQUIT to the process.
I've only observed this when using cgo.
/cc @mknyszek
The text was updated successfully, but these errors were encountered: