Hi gophers,
I hope someone can help finding out why a particular goroutine call can block the main goroutine.
In the following code, all "go" calls spawn off a goroutine and return as expected, except for the last one that blocks the main goroutine.
Is this a bug, or am I missing something subtle or even obvious (obvious to all others only of course)?
package main
import (
"log"
"net/http"
)
func main() {
// all of these work as expected
go http.ListenAndServe("localhost:8080", nil)
go log.Println("goroutine")
go func() {
log.Println(http.ListenAndServe("localhost:8081", nil))
}()
// The following line blocks the main goroutine.
go log.Println(http.ListenAndServe("localhost:8082", nil))
log.Println("after go log.Println(http.ListenAndServe())") // never prints
select {} // remove this, and the code still never finishes
}
All three servers eventually run (try curl localhost:8080; curl localhost:8081; curl localhost:8082),
Any idea?