Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't this code return a "deadlock" error?

Tags:

go

deadlock

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.

like image 336
wei Avatar asked Dec 23 '22 20:12

wei


1 Answers

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

like image 131
Tiya Jose Avatar answered Dec 30 '22 17:12

Tiya Jose