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: cgo using programs have a goroutine marked [syscall, locked to thread]; make it clearer #16714

Closed
shiyanhui opened this issue Aug 16, 2016 · 7 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@shiyanhui
Copy link

shiyanhui commented Aug 16, 2016

Please answer these questions before submitting your issue. Thanks!

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

    go1.6
    go1.6.3
    go1.7
    

    All tried.

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

    GOARCH="amd64"
    GOBIN=""
    GOEXE=""
    GOHOSTARCH="amd64"
    GOHOSTOS="linux"
    GOOS="linux"
    GOPATH="/root/work"
    GORACE=""
    GOROOT="/root/go"
    GOTOOLDIR="/root/go/pkg/tool/linux_amd64"
    CC="gcc"
    GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go- build476293257=/tmp/go-build -gno-record-gcc-switches"
    CXX="g++"
    CGO_ENABLED="1"
    
  3. What did you do?

    DHT implements BitTorrent DHT Protocol. It sends and receives UDP packets.

    go get github.com/shiyanhui/dht
    cd github.com/shiyanhui/dht/sample/spider
    go build spider.go
    nohup ./spider &
    curl http://localhost:6060/debug/pprof/goroutine?debug=2
    

    And you will see it.

  4. What did you expect to see?

    Not blocked, maybe [syscall, locked to thread]

  5. What did you see instead?

    [syscall, 214 minutes, locked to thread], always blocked. It can be repeatable.

@minux
Copy link
Member

minux commented Aug 16, 2016 via email

@shiyanhui
Copy link
Author

It's here. shiyanhui/dht#6 (comment)

@ianlancetaylor ianlancetaylor changed the title [syscall, 214 minutes, locked to thread] blocked for 214 minutes, is it normal? runtime: [syscall, 214 minutes, locked to thread] blocked for 214 minutes, is it normal? Aug 16, 2016
@ianlancetaylor ianlancetaylor added this to the Go1.8 milestone Aug 16, 2016
@ianlancetaylor
Copy link
Contributor

I don't understand why this goroutine does not show any stack trace.

Is there a way that we can recreate the problem ourselves?

@jbardin
Copy link
Contributor

jbardin commented Aug 16, 2016

@ianlancetaylor,

Most programs that import "net" will have this goroutine:

import _ "net"

func main() {
    panic("done")
}

I always assumed it was a cgo finalizer, since the goroutine doesn't appear with CGO_ENABLED=0

@shiyanhui
Copy link
Author

I tried it with CGO_ENABLED=0 and [syscall, locked to thread] is gone.

@ianlancetaylor
Copy link
Contributor

@jbardin Thanks for pointing that out. That explains it. It's not a finalizer goroutine (which indicates its status with "finalizer"). It's a spare goroutine that is created for any Go program that uses cgo in case a thread started by C code calls a Go function.

So this is completely normal. I will leave this issue open to make it appear less odd in a stack trace, such as by using a function other than goexit. For the record, it can be seen by running the above trivial program with GOTRACEBACK=system.

@ianlancetaylor ianlancetaylor changed the title runtime: [syscall, 214 minutes, locked to thread] blocked for 214 minutes, is it normal? runtime: cgo using programs have a goroutine marked [syscall, locked to thread]; make it clearer Aug 17, 2016
@quentinmit quentinmit added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 11, 2016
@rsc rsc modified the milestones: Go1.9, Go1.8 Nov 11, 2016
@gopherbot
Copy link

CL https://golang.org/cl/45030 mentions this issue.

@golang golang locked and limited conversation to collaborators Jun 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

7 participants