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

go 1.5.1 linux/amd64 deadlock detection failed #12734

Closed
wudizhanche1000 opened this issue Sep 24, 2015 · 2 comments
Closed

go 1.5.1 linux/amd64 deadlock detection failed #12734

wudizhanche1000 opened this issue Sep 24, 2015 · 2 comments

Comments

@wudizhanche1000
Copy link

package main

import (
    "log"
    "net/http"
)
//delete this function, it would perform well
func useless_func(address string) []byte {
    http.Get("https://www.google.com")
    return nil
}
func test_a(test_channel chan int) {
    test_channel <- 1
    return
}

func test() {
    test_channel := make(chan int)
    for i := 0; i < 10; i++ {
        go test_a(test_channel)
    }
    for {
        log.Println(<-test_channel)
    }
}
func main() {
    test()
}

this code won't break because of clearly deadlock, it only happened under Linux with go 1.5.1. but if i delete useless_func and run it again, it would raise a deadlock error as expected.

@bradfitz
Copy link
Contributor

Importing the net package disables the deadlock detector. It has nothing to do with net/http or that func. For example, this also doesn't catch the deadlock:

package main

import "log"
import _ "net"

func test_a(test_channel chan int) {
        test_channel <- 1
        return
}

func test() {
        test_channel := make(chan int)
        for i := 0; i < 10; i++ {
                go test_a(test_channel)
        }
        for {
                log.Println(<-test_channel)
        }
}
func main() {
        test()
}

The deadlock detector makes no guarantees. It basically only catches things with the most trivial programs.

@dominikh
Copy link
Member

To expand: The issue really lies with using cgo (which net uses, ignoring the details). When using cgo, the Go deadlock detection cannot function properly, because C world might call Go functions at any time, so in theory no deadlock exists; we might just be waiting for an external function call indefinitely.

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