简体   繁体   中英

Why doesn't this code return a “deadlock” error?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM