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

caller of func called by goroutine is goexit #41423

Closed
wjh000123 opened this issue Sep 16, 2020 · 3 comments
Closed

caller of func called by goroutine is goexit #41423

wjh000123 opened this issue Sep 16, 2020 · 3 comments

Comments

@wjh000123
Copy link

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

$ go version
go1.14.8

Does this issue reproduce with the latest release?

yes

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

go env Output
$ go env

What did you do?

get caller of some func
https://play.golang.org/p/gKjf1xNTCOK

What did you expect to see?

see the correct caller

What did you see instead?

for func called in goroutine mode, the caller is goexit

@davecheney
Copy link
Contributor

This is caused by inlining. I don’t believe there is a bug here.

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For asking questions, see:

@randall77
Copy link
Contributor

I don't think this has anything directly to do with inlining. It's just that in

func f() {
    go g()
}

f is not the caller of g. At least, not according to the runtime. For instance, the stack frame of f can be long gone while g is still running.

The caller of the function g is goexit. That's just a placeholder, we could just as well have decided that g doesn't have a caller. But goexit makes it clear that when g returns, the goroutine is going to exit (ala runtime.Goexit).

If you want to know where a goroutine was spawned from, that information is available in the output of runtime.Stack.

@wjh000123
Copy link
Author

@randall77 thanks for your detail explanation!

What I want to do is to create a helper function to track caller in log without any injection code. After investigation, I did find runtime.Stack could do the trick, but somehow it is not elegant, and also performance.

It could be better to have a new function to get the spawner.

@golang golang locked and limited conversation to collaborators Sep 17, 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