On Mon, Feb 22, 2021 at 12:22 PM Peng Yu <[email protected]> wrote: > > I run the following go program using net.Dial(). Depending on whether > I specify a local hostname (defined in /etc/hosts) or an IP. I get > very different runtimes. > > But `ping mymachine.local` resolves the hostname to an IP address > instantaneously. So the two calls of the go program should have the > same runtimes. > > Can anybody reproduce the same runtime problem? Does anybody know what > is wrong with the implementation of net.Dial()? Thanks. > > $ ./main mymachine.local:22 > 2021/02/22 14:14:25 before > 2021/02/22 14:14:30 after > $ ./main 192.168.1.104:22 > 2021/02/22 14:14:30 before > 2021/02/22 14:14:30 after > $ cat main.go > package main > import ( > "net" > "log" > "os" > ) > > func main() { > dialAddr := os.Args[1] > log.Println("before") > _, err := net.Dial("tcp", dialAddr) > log.Println("after") > if err != nil { > log.Fatalln(err) > } > }
Which version of Go are you using? What operating system are you running on? It is possible that are running into https://golang.org/issue/35305, which is fixed in 1.16. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcWQvAH5yVytaPkPLhh%3DJ5x9Hh4GD-d4O2tKURC699gA1A%40mail.gmail.com.
