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

Comments

Projects
None yet
7 participants
@shiyanhui
Copy link

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

This comment has been minimized.

Copy link
Member

commented Aug 16, 2016

@shiyanhui

This comment has been minimized.

Copy link
Author

commented Aug 16, 2016

@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

This comment has been minimized.

Copy link
Contributor

commented Aug 16, 2016

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

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Author

commented Aug 17, 2016

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

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Aug 17, 2016

@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 label Oct 11, 2016

@rsc rsc modified the milestones: Go1.9, Go1.8 Nov 11, 2016

@gopherbot

This comment has been minimized.

Copy link

commented Jun 6, 2017

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

@gopherbot gopherbot closed this in 4e7067c Jun 7, 2017

@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.
You can’t perform that action at this time.