问题
package main
import (
"fmt"
"net/http"
)
func Extract(url string) ([]string, error) {
http.Get(url)
var links []string
return links, nil
}
func crawl(url string) []string {
list, _ := Extract(url)
return list
}
func main() {
var ch = make(chan int)
ch <- 1
}
If I remove the net/http import, it will return a "deadlock" error as expected. But if I import this package, although I didn't invoke the Extract func, the "deadlock" will not appear.
回答1:
Importing the net package starts background polling Goroutines that effectively disable the deadlock detector.
You can see the discussion for a similar issue here: https://github.com/golang/go/issues/12734
来源:https://stackoverflow.com/questions/58619289/why-doesnt-this-code-return-a-deadlock-error