Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-23 Thread robert engels
I would refer you back to the other article I linked to on setting up your host 
name properly.

When I test using the default DNS resolving I can resolve both ‘iMac’ and 
‘iMac.local’ in 2-3 milliseconds without any entry in my /etc/hosts file.  If I 
add the entry ‘iMac.local’ to my /etc/hosts file it still resolves fine.

When I use a invalid hostname, it is 5 seconds - always. It appears it is using 
a CGo/Library path that bypasses the DNS cache.

Note that this differs from the Go DNS resolver (using GODEBUG=netdns=Go) where 
it is only 5 seconds at most the first time, then it is cached for some period 
of time across process restarts, so that subsequent ‘invalid’ queries only take 
a few milliseconds.

> On Feb 23, 2021, at 11:51 AM, Peng Yu  wrote:
> 
>>> I don’t understand why ping does not have the same problem. Ping is not
>>> based on C library?
>>> 
>> 
>> Looking at the source code, the ping command on macOS use gethostbyname2()
>> [1][2], while the Go on macOS use C library through getaddrinfo [3][4].
> 
> If so, I'd consider it as a performance bug of net.Dial() on macOS.
> After all, the following command runs quickly to resolve an IP address
> from a name (suffixed with .local) in /etc/hosts much faster. So
> net.Dial() could (and probably should) just use this (or something
> along this line) on macOS to fix the performance problem.
> 
> net.ResolveIPAddr("ip4", addr)
> 
> -- 
> Regards,
> Peng
> 
> -- 
> 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 golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/CABrM6w%3Dfb_BXwdbcfJzfrMafRhfj6mxzVZ_5udx9yo5iFpWgSw%40mail.gmail.com.

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/0883DD9C-7F6D-483F-BE1B-F7BDE1E029EB%40ix.netcom.com.


Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-23 Thread Peng Yu
>> I don’t understand why ping does not have the same problem. Ping is not
>> based on C library?
>>
>
> Looking at the source code, the ping command on macOS use gethostbyname2()
> [1][2], while the Go on macOS use C library through getaddrinfo [3][4].

If so, I'd consider it as a performance bug of net.Dial() on macOS.
After all, the following command runs quickly to resolve an IP address
from a name (suffixed with .local) in /etc/hosts much faster. So
net.Dial() could (and probably should) just use this (or something
along this line) on macOS to fix the performance problem.

net.ResolveIPAddr("ip4", addr)

-- 
Regards,
Peng

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CABrM6w%3Dfb_BXwdbcfJzfrMafRhfj6mxzVZ_5udx9yo5iFpWgSw%40mail.gmail.com.


Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-23 Thread Robert Engels
Nice work. 

> On Feb 23, 2021, at 10:16 AM, Shulhan  wrote:
> 
> 
>> On 23 Feb 2021, at 12.40, Peng Yu  wrote:
>> 
>> I don’t understand why ping does not have the same problem. Ping is not 
>> based on C library?
>> 
> 
> Looking at the source code, the ping command on macOS use gethostbyname2() 
> [1][2], while the Go on macOS use C library through getaddrinfo [3][4].
> 
> According to this comment [5] on bugs.python.org, the getaddrinfo call mdns 
> library, which means it may prioritise to broadcast through network first 
> (due to local TLD rule) before consulting the /etc/hosts file.
> 
> That is my guess. Maybe someone who know macOS (or BSD in general) can 
> confirm this behaviour.
> 
> --
> 
> [1] 
> https://opensource.apple.com/source/network_cmds/network_cmds-606.40.2/ping.tproj/ping.c.auto.html
> 
> [2] 
> https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/gethostbyname.3.html
> 
> [3] https://go.googlesource.com/go/+/go1.16/src/net/cgo_unix.go#161
> 
> [4] 
> https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/getaddrinfo.3.html#//apple_ref/doc/man/3/getaddrinfo
> 
> [5] https://bugs.python.org/msg258163
> 
>> On Mon, Feb 22, 2021 at 11:20 PM Ian Lance Taylor  wrote:
>>> On Mon, Feb 22, 2021 at 9:11 PM Peng Yu  wrote:
>>> 
>>> I tried 1.16.
>>> 
>>> $ go version
>>> go version go1.16 darwin/amd64
>>> 
>>> The problem still exists. When I change mymachine.local to
>>> mymachine_local, the problem is gone. So somehow, this is related to
>>> host resolution? It might try to DNS lookup the hostname, when it can
>>> not find it via DNS then it look up in /etc/hosts?
>> 
>> On Darwin I believe that by default we pass DNS lookups to the C
>> library.  So I think that what you are seeing is the behavior of the C
>> library.  Try setting the environment variable GODEBUG=netdns=go.
>> 
>> Ian
>> 
>> 
>>> On 2/22/21, Ian Lance Taylor  wrote:
 On Mon, Feb 22, 2021 at 12:22 PM Peng Yu  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
 
>>> 
>>> 
>>> --
>>> Regards,
>>> Peng
>> -- 
>> Regards,
>> Peng
>> 
>> -- 
>> 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 golang-nuts+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/CABrM6w%3D8Orgj3t4MW3%3DMs7L0vy0nFS_EeGjRZ8n%2BTvQOrHAO9g%40mail.gmail.com.
> 
> -- 
> 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 golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/A0FD8A6A-8159-46C0-AD66-575E2C040AA5%40gmail.com.

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/578BFBEF-4888-4868-8B6C-96172AED7FFC%40ix.netcom.com.


Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-23 Thread Shulhan


> On 23 Feb 2021, at 12.40, Peng Yu  wrote:
> 
> I don’t understand why ping does not have the same problem. Ping is not based 
> on C library?
> 

Looking at the source code, the ping command on macOS use gethostbyname2() 
[1][2], while the Go on macOS use C library through getaddrinfo [3][4].

According to this comment [5] on bugs.python.org, the getaddrinfo call mdns 
library, which means it may prioritise to broadcast through network first (due 
to local TLD rule) before consulting the /etc/hosts file.

That is my guess. Maybe someone who know macOS (or BSD in general) can confirm 
this behaviour.

--

[1] 
https://opensource.apple.com/source/network_cmds/network_cmds-606.40.2/ping.tproj/ping.c.auto.html

[2] 
https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/gethostbyname.3.html

[3] https://go.googlesource.com/go/+/go1.16/src/net/cgo_unix.go#161

[4] 
https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/getaddrinfo.3.html#//apple_ref/doc/man/3/getaddrinfo

[5] https://bugs.python.org/msg258163

> On Mon, Feb 22, 2021 at 11:20 PM Ian Lance Taylor  wrote:
> On Mon, Feb 22, 2021 at 9:11 PM Peng Yu  wrote:
> >
> > I tried 1.16.
> >
> > $ go version
> > go version go1.16 darwin/amd64
> >
> > The problem still exists. When I change mymachine.local to
> > mymachine_local, the problem is gone. So somehow, this is related to
> > host resolution? It might try to DNS lookup the hostname, when it can
> > not find it via DNS then it look up in /etc/hosts?
> 
> On Darwin I believe that by default we pass DNS lookups to the C
> library.  So I think that what you are seeing is the behavior of the C
> library.  Try setting the environment variable GODEBUG=netdns=go.
> 
> Ian
> 
> 
> > On 2/22/21, Ian Lance Taylor  wrote:
> > > On Mon, Feb 22, 2021 at 12:22 PM Peng Yu  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
> > >
> >
> >
> > --
> > Regards,
> > Peng
> -- 
> Regards,
> Peng
> 
> -- 
> 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 golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/CABrM6w%3D8Orgj3t4MW3%3DMs7L0vy0nFS_EeGjRZ8n%2BTvQOrHAO9g%40mail.gmail.com.

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/A0FD8A6A-8159-46C0-AD66-575E2C040AA5%40gmail.com.


Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-23 Thread Robert Engels
I looked into it more. You can use GODEBUG to configure to use the Go dns 
resolver - but even if you don’t there is a significant Go layer to Dial - it 
is not a simple pass through to the C call. 

> On Feb 23, 2021, at 8:54 AM, Kevin Chadwick  wrote:
> 
> On February 23, 2021 2:46:20 PM UTC, Robert Engels  
> wrote:
>> I am not 100% certain but the build statement at the top of the Unix
>> dns client specified Darwin. I would read the Go issues I linked to in
>> the code snippet. 
> 
> I believe it varies. Android has no universal textual interface - 
> /etc/resolv.conf, for example.
> 
> -- 
> 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 golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/218CEFB4-B03F-4284-B62B-AFB2B1C2032A%40gmail.com.

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/67F279B6-B73C-419D-A15D-FD098FDEEEA8%40ix.netcom.com.


Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-23 Thread Kevin Chadwick
On February 23, 2021 2:46:20 PM UTC, Robert Engels  
wrote:
>I am not 100% certain but the build statement at the top of the Unix
>dns client specified Darwin. I would read the Go issues I linked to in
>the code snippet. 

I believe it varies. Android has no universal textual interface - 
/etc/resolv.conf, for example.

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/218CEFB4-B03F-4284-B62B-AFB2B1C2032A%40gmail.com.


Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-23 Thread Robert Engels
I am not 100% certain but the build statement at the top of the Unix dns client 
specified Darwin. I would read the Go issues I linked to in the code snippet. 

> On Feb 23, 2021, at 8:29 AM, Peng Yu  wrote:
> 
> Hi Robert,
> 
> Ian Lance Taylor said the exact opposite. "On Darwin I believe that by
> default we pass DNS lookups to the C
> library." (I assume "we" means Go developers.)
> 
> Are you correct or Ian is correct?
> 
>> On Tue, Feb 23, 2021 at 8:14 AM Robert Engels  wrote:
>> 
>> As I pointed out, Go does not use the C library.
>> 
 On Feb 23, 2021, at 7:57 AM, Peng Yu  wrote:
>>> 
>>> This does not answer the question why net.Dial can not be made with
>>> the same behavior as ping on MacOSX. If the C library behaves
>>> differently on MacOSX and Linux, then the C library should not be
>>> relied on in this case. I just want to use /etc/hosts but not
>>> resolve.conf.
>>> 
 On 2/22/21, robert engels  wrote:
 It looks like the Go runtime implements its own DNS client on *unix
 platforms including OSX.
 
>> On Feb 22, 2021, at 11:40 PM, Peng Yu  wrote:
> 
> I don’t understand why ping does not have the same problem. Ping is not
> based on C library?
> 
> On Mon, Feb 22, 2021 at 11:20 PM Ian Lance Taylor  > wrote:
> On Mon, Feb 22, 2021 at 9:11 PM Peng Yu  > wrote:
>> 
>> I tried 1.16.
>> 
>> $ go version
>> go version go1.16 darwin/amd64
>> 
>> The problem still exists. When I change mymachine.local to
>> mymachine_local, the problem is gone. So somehow, this is related to
>> host resolution? It might try to DNS lookup the hostname, when it can
>> not find it via DNS then it look up in /etc/hosts?
> 
> On Darwin I believe that by default we pass DNS lookups to the C
> library.  So I think that what you are seeing is the behavior of the C
> library.  Try setting the environment variable GODEBUG=netdns=go.
> 
> Ian
> 
> 
>> On 2/22/21, Ian Lance Taylor mailto:i...@golang.org>>
>> wrote:
>>> On Mon, Feb 22, 2021 at 12:22 PM Peng Yu >> > 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
>>> 
>> 
>> 
>> --
>> Regards,
>> Peng
> --
> Regards,
> Peng
> 
> --
> 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 golang-nuts+unsubscr...@googlegroups.com
> .
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/CABrM6w%3D8Orgj3t4MW3%3DMs7L0vy0nFS_EeGjRZ8n%2BTvQOrHAO9g%40mail.gmail.com
> .
 
 
>>> 
>>> 
>>> --
>>> Regards,
>>> Peng
>>> 
>>> --
>>> 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 golang-nuts+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/golang-nuts/CABrM6wkmMj7GgAckj6%3DcHZqd0vxnH0735%2BAc4n7zV%3D%3DBhD4Z8Q%40mail.gmail.com.
>> 
> 
> 
> -- 
> Regards,
> Peng

-- 
You received this message because you are subscribed to the 

Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-23 Thread Peng Yu
Hi Robert,

Ian Lance Taylor said the exact opposite. "On Darwin I believe that by
default we pass DNS lookups to the C
library." (I assume "we" means Go developers.)

Are you correct or Ian is correct?

On Tue, Feb 23, 2021 at 8:14 AM Robert Engels  wrote:
>
> As I pointed out, Go does not use the C library.
>
> > On Feb 23, 2021, at 7:57 AM, Peng Yu  wrote:
> >
> > This does not answer the question why net.Dial can not be made with
> > the same behavior as ping on MacOSX. If the C library behaves
> > differently on MacOSX and Linux, then the C library should not be
> > relied on in this case. I just want to use /etc/hosts but not
> > resolve.conf.
> >
> >> On 2/22/21, robert engels  wrote:
> >> It looks like the Go runtime implements its own DNS client on *unix
> >> platforms including OSX.
> >>
>  On Feb 22, 2021, at 11:40 PM, Peng Yu  wrote:
> >>>
> >>> I don’t understand why ping does not have the same problem. Ping is not
> >>> based on C library?
> >>>
> >>> On Mon, Feb 22, 2021 at 11:20 PM Ian Lance Taylor  >>> > wrote:
> >>> On Mon, Feb 22, 2021 at 9:11 PM Peng Yu  >>> > wrote:
> 
>  I tried 1.16.
> 
>  $ go version
>  go version go1.16 darwin/amd64
> 
>  The problem still exists. When I change mymachine.local to
>  mymachine_local, the problem is gone. So somehow, this is related to
>  host resolution? It might try to DNS lookup the hostname, when it can
>  not find it via DNS then it look up in /etc/hosts?
> >>>
> >>> On Darwin I believe that by default we pass DNS lookups to the C
> >>> library.  So I think that what you are seeing is the behavior of the C
> >>> library.  Try setting the environment variable GODEBUG=netdns=go.
> >>>
> >>> Ian
> >>>
> >>>
>  On 2/22/21, Ian Lance Taylor mailto:i...@golang.org>>
>  wrote:
> > On Mon, Feb 22, 2021 at 12:22 PM Peng Yu  > > 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
> >
> 
> 
>  --
>  Regards,
>  Peng
> >>> --
> >>> Regards,
> >>> Peng
> >>>
> >>> --
> >>> 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 golang-nuts+unsubscr...@googlegroups.com
> >>> .
> >>> To view this discussion on the web visit
> >>> https://groups.google.com/d/msgid/golang-nuts/CABrM6w%3D8Orgj3t4MW3%3DMs7L0vy0nFS_EeGjRZ8n%2BTvQOrHAO9g%40mail.gmail.com
> >>> .
> >>
> >>
> >
> >
> > --
> > Regards,
> > Peng
> >
> > --
> > 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 golang-nuts+unsubscr...@googlegroups.com.
> > To view this discussion on the web visit 
> > https://groups.google.com/d/msgid/golang-nuts/CABrM6wkmMj7GgAckj6%3DcHZqd0vxnH0735%2BAc4n7zV%3D%3DBhD4Z8Q%40mail.gmail.com.
>


-- 
Regards,
Peng

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 

Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-23 Thread Kevin Chadwick
On February 23, 2021 1:57:07 PM UTC, Peng Yu  wrote:
>This does not answer the question why net.Dial can not be made with
>the same behavior as ping on MacOSX. If the C library behaves
>differently on MacOSX and Linux, then the C library should not be
>relied on in this case. I just want to use /etc/hosts but not
>resolve.conf.
>

There is a setting to use gos DNS, I believe. You could always parse /etc/hosts 
and make a connection. If it's slow it us likely a timeout/mis configuration.

Generally you want to use whatever dns elaborations that the system provides or 
user has chosen, like mdns, doh, dotls, dnssec, unbound, unwind...

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/353AC292-2AAD-45C8-BCEC-0E7FDBD68B9B%40gmail.com.


Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-23 Thread Robert Engels
As I pointed out, Go does not use the C library. 

> On Feb 23, 2021, at 7:57 AM, Peng Yu  wrote:
> 
> This does not answer the question why net.Dial can not be made with
> the same behavior as ping on MacOSX. If the C library behaves
> differently on MacOSX and Linux, then the C library should not be
> relied on in this case. I just want to use /etc/hosts but not
> resolve.conf.
> 
>> On 2/22/21, robert engels  wrote:
>> It looks like the Go runtime implements its own DNS client on *unix
>> platforms including OSX.
>> 
 On Feb 22, 2021, at 11:40 PM, Peng Yu  wrote:
>>> 
>>> I don’t understand why ping does not have the same problem. Ping is not
>>> based on C library?
>>> 
>>> On Mon, Feb 22, 2021 at 11:20 PM Ian Lance Taylor >> > wrote:
>>> On Mon, Feb 22, 2021 at 9:11 PM Peng Yu >> > wrote:
 
 I tried 1.16.
 
 $ go version
 go version go1.16 darwin/amd64
 
 The problem still exists. When I change mymachine.local to
 mymachine_local, the problem is gone. So somehow, this is related to
 host resolution? It might try to DNS lookup the hostname, when it can
 not find it via DNS then it look up in /etc/hosts?
>>> 
>>> On Darwin I believe that by default we pass DNS lookups to the C
>>> library.  So I think that what you are seeing is the behavior of the C
>>> library.  Try setting the environment variable GODEBUG=netdns=go.
>>> 
>>> Ian
>>> 
>>> 
 On 2/22/21, Ian Lance Taylor mailto:i...@golang.org>>
 wrote:
> On Mon, Feb 22, 2021 at 12:22 PM Peng Yu  > 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
> 
 
 
 --
 Regards,
 Peng
>>> --
>>> Regards,
>>> Peng
>>> 
>>> --
>>> 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 golang-nuts+unsubscr...@googlegroups.com
>>> .
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/golang-nuts/CABrM6w%3D8Orgj3t4MW3%3DMs7L0vy0nFS_EeGjRZ8n%2BTvQOrHAO9g%40mail.gmail.com
>>> .
>> 
>> 
> 
> 
> -- 
> Regards,
> Peng
> 
> -- 
> 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 golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/CABrM6wkmMj7GgAckj6%3DcHZqd0vxnH0735%2BAc4n7zV%3D%3DBhD4Z8Q%40mail.gmail.com.

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/51439421-53DB-4E7B-A591-E29F688AC415%40ix.netcom.com.


Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-23 Thread Peng Yu
This does not answer the question why net.Dial can not be made with
the same behavior as ping on MacOSX. If the C library behaves
differently on MacOSX and Linux, then the C library should not be
relied on in this case. I just want to use /etc/hosts but not
resolve.conf.

On 2/22/21, robert engels  wrote:
> It looks like the Go runtime implements its own DNS client on *unix
> platforms including OSX.
>
>> On Feb 22, 2021, at 11:40 PM, Peng Yu  wrote:
>>
>> I don’t understand why ping does not have the same problem. Ping is not
>> based on C library?
>>
>> On Mon, Feb 22, 2021 at 11:20 PM Ian Lance Taylor > > wrote:
>> On Mon, Feb 22, 2021 at 9:11 PM Peng Yu > > wrote:
>> >
>> > I tried 1.16.
>> >
>> > $ go version
>> > go version go1.16 darwin/amd64
>> >
>> > The problem still exists. When I change mymachine.local to
>> > mymachine_local, the problem is gone. So somehow, this is related to
>> > host resolution? It might try to DNS lookup the hostname, when it can
>> > not find it via DNS then it look up in /etc/hosts?
>>
>> On Darwin I believe that by default we pass DNS lookups to the C
>> library.  So I think that what you are seeing is the behavior of the C
>> library.  Try setting the environment variable GODEBUG=netdns=go.
>>
>> Ian
>>
>>
>> > On 2/22/21, Ian Lance Taylor mailto:i...@golang.org>>
>> > wrote:
>> > > On Mon, Feb 22, 2021 at 12:22 PM Peng Yu > > > > 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
>> > >
>> >
>> >
>> > --
>> > Regards,
>> > Peng
>> --
>> Regards,
>> Peng
>>
>> --
>> 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 golang-nuts+unsubscr...@googlegroups.com
>> .
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/golang-nuts/CABrM6w%3D8Orgj3t4MW3%3DMs7L0vy0nFS_EeGjRZ8n%2BTvQOrHAO9g%40mail.gmail.com
>> .
>
>


-- 
Regards,
Peng

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CABrM6wkmMj7GgAckj6%3DcHZqd0vxnH0735%2BAc4n7zV%3D%3DBhD4Z8Q%40mail.gmail.com.


Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-22 Thread robert engels
There is also this note in the /etc/resolv.conf file:

#
# macOS Notice
#
# This file is not consulted for DNS hostname resolution, address
# resolution, or the DNS query routing mechanism used by most
# processes on this system.

but the Go DNS client uses resolv.conf for its configuration - that may be the 
source of the problem. But there is also this code in the stdlib:

// avoidDNS reports whether this is a hostname for which we should not
// use DNS. Currently this includes only .onion, per RFC 7686. See
// golang.org/issue/13705. Does not cover .local names (RFC 6762),
// see golang.org/issue/16739.
func avoidDNS(name string) bool {
   if name == "" {
  return true
   }
   if name[len(name)-1] == '.' {
  name = name[:len(name)-1]
   }
   return stringsHasSuffixFold(name, ".onion")
}
so Go issue 16739 might help.

> On Feb 22, 2021, at 11:51 PM, robert engels  wrote:
> 
> Still, if you follow that article I referred you to it may fix your issue - 
> as the resolv.conf is auto-generated on OSX and includes hostname mappings.
> 
>> On Feb 22, 2021, at 11:48 PM, robert engels > > wrote:
>> 
>> It looks like the Go runtime implements its own DNS client on *unix 
>> platforms including OSX.
>> 
>>> On Feb 22, 2021, at 11:40 PM, Peng Yu >> > wrote:
>>> 
>>> I don’t understand why ping does not have the same problem. Ping is not 
>>> based on C library?
>>> 
>>> On Mon, Feb 22, 2021 at 11:20 PM Ian Lance Taylor >> > wrote:
>>> On Mon, Feb 22, 2021 at 9:11 PM Peng Yu >> > wrote:
>>> >
>>> > I tried 1.16.
>>> >
>>> > $ go version
>>> > go version go1.16 darwin/amd64
>>> >
>>> > The problem still exists. When I change mymachine.local to
>>> > mymachine_local, the problem is gone. So somehow, this is related to
>>> > host resolution? It might try to DNS lookup the hostname, when it can
>>> > not find it via DNS then it look up in /etc/hosts?
>>> 
>>> On Darwin I believe that by default we pass DNS lookups to the C
>>> library.  So I think that what you are seeing is the behavior of the C
>>> library.  Try setting the environment variable GODEBUG=netdns=go.
>>> 
>>> Ian
>>> 
>>> 
>>> > On 2/22/21, Ian Lance Taylor mailto:i...@golang.org>> 
>>> > wrote:
>>> > > On Mon, Feb 22, 2021 at 12:22 PM Peng Yu >> > > > 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
>>> > >
>>> >
>>> >
>>> > --
>>> > Regards,
>>> > Peng
>>> -- 
>>> Regards,
>>> Peng
>>> 
>>> -- 
>>> 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 golang-nuts+unsubscr...@googlegroups.com 
>>> .
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/golang-nuts/CABrM6w%3D8Orgj3t4MW3%3DMs7L0vy0nFS_EeGjRZ8n%2BTvQOrHAO9g%40mail.gmail.com
>>>  
>>> .
>> 
> 

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/AE00E72A-F08D-4328-9391-76FA7BCD9038%40ix.netcom.com.


Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-22 Thread robert engels
Still, if you follow that article I referred you to it may fix your issue - as 
the resolv.conf is auto-generated on OSX and includes hostname mappings.

> On Feb 22, 2021, at 11:48 PM, robert engels  wrote:
> 
> It looks like the Go runtime implements its own DNS client on *unix platforms 
> including OSX.
> 
>> On Feb 22, 2021, at 11:40 PM, Peng Yu > > wrote:
>> 
>> I don’t understand why ping does not have the same problem. Ping is not 
>> based on C library?
>> 
>> On Mon, Feb 22, 2021 at 11:20 PM Ian Lance Taylor > > wrote:
>> On Mon, Feb 22, 2021 at 9:11 PM Peng Yu > > wrote:
>> >
>> > I tried 1.16.
>> >
>> > $ go version
>> > go version go1.16 darwin/amd64
>> >
>> > The problem still exists. When I change mymachine.local to
>> > mymachine_local, the problem is gone. So somehow, this is related to
>> > host resolution? It might try to DNS lookup the hostname, when it can
>> > not find it via DNS then it look up in /etc/hosts?
>> 
>> On Darwin I believe that by default we pass DNS lookups to the C
>> library.  So I think that what you are seeing is the behavior of the C
>> library.  Try setting the environment variable GODEBUG=netdns=go.
>> 
>> Ian
>> 
>> 
>> > On 2/22/21, Ian Lance Taylor mailto:i...@golang.org>> 
>> > wrote:
>> > > On Mon, Feb 22, 2021 at 12:22 PM Peng Yu > > > > 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
>> > >
>> >
>> >
>> > --
>> > Regards,
>> > Peng
>> -- 
>> Regards,
>> Peng
>> 
>> -- 
>> 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 golang-nuts+unsubscr...@googlegroups.com 
>> .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/CABrM6w%3D8Orgj3t4MW3%3DMs7L0vy0nFS_EeGjRZ8n%2BTvQOrHAO9g%40mail.gmail.com
>>  
>> .
> 

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/DCAD440F-746D-4EA6-B3E5-5238C0F6F421%40ix.netcom.com.


Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-22 Thread robert engels
It looks like the Go runtime implements its own DNS client on *unix platforms 
including OSX.

> On Feb 22, 2021, at 11:40 PM, Peng Yu  wrote:
> 
> I don’t understand why ping does not have the same problem. Ping is not based 
> on C library?
> 
> On Mon, Feb 22, 2021 at 11:20 PM Ian Lance Taylor  > wrote:
> On Mon, Feb 22, 2021 at 9:11 PM Peng Yu  > wrote:
> >
> > I tried 1.16.
> >
> > $ go version
> > go version go1.16 darwin/amd64
> >
> > The problem still exists. When I change mymachine.local to
> > mymachine_local, the problem is gone. So somehow, this is related to
> > host resolution? It might try to DNS lookup the hostname, when it can
> > not find it via DNS then it look up in /etc/hosts?
> 
> On Darwin I believe that by default we pass DNS lookups to the C
> library.  So I think that what you are seeing is the behavior of the C
> library.  Try setting the environment variable GODEBUG=netdns=go.
> 
> Ian
> 
> 
> > On 2/22/21, Ian Lance Taylor mailto:i...@golang.org>> 
> > wrote:
> > > On Mon, Feb 22, 2021 at 12:22 PM Peng Yu  > > > 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
> > >
> >
> >
> > --
> > Regards,
> > Peng
> -- 
> Regards,
> Peng
> 
> -- 
> 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 golang-nuts+unsubscr...@googlegroups.com 
> .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/CABrM6w%3D8Orgj3t4MW3%3DMs7L0vy0nFS_EeGjRZ8n%2BTvQOrHAO9g%40mail.gmail.com
>  
> .

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/2E9EE048-6CDF-4B35-85E2-7BFD5F76C500%40ix.netcom.com.


Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-22 Thread Peng Yu
I don’t understand why ping does not have the same problem. Ping is not
based on C library?

On Mon, Feb 22, 2021 at 11:20 PM Ian Lance Taylor  wrote:

> On Mon, Feb 22, 2021 at 9:11 PM Peng Yu  wrote:
> >
> > I tried 1.16.
> >
> > $ go version
> > go version go1.16 darwin/amd64
> >
> > The problem still exists. When I change mymachine.local to
> > mymachine_local, the problem is gone. So somehow, this is related to
> > host resolution? It might try to DNS lookup the hostname, when it can
> > not find it via DNS then it look up in /etc/hosts?
>
> On Darwin I believe that by default we pass DNS lookups to the C
> library.  So I think that what you are seeing is the behavior of the C
> library.  Try setting the environment variable GODEBUG=netdns=go.
>
> Ian
>
>
> > On 2/22/21, Ian Lance Taylor  wrote:
> > > On Mon, Feb 22, 2021 at 12:22 PM Peng Yu  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
> > >
> >
> >
> > --
> > Regards,
> > Peng
>
-- 
Regards,
Peng

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CABrM6w%3D8Orgj3t4MW3%3DMs7L0vy0nFS_EeGjRZ8n%2BTvQOrHAO9g%40mail.gmail.com.


Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-22 Thread robert engels
This 
https://apple.stackexchange.com/questions/175320/why-is-my-hostname-resolution-taking-so-long
 

 may help you.

> On Feb 22, 2021, at 11:20 PM, Ian Lance Taylor  wrote:
> 
> On Mon, Feb 22, 2021 at 9:11 PM Peng Yu  > wrote:
>> 
>> I tried 1.16.
>> 
>> $ go version
>> go version go1.16 darwin/amd64
>> 
>> The problem still exists. When I change mymachine.local to
>> mymachine_local, the problem is gone. So somehow, this is related to
>> host resolution? It might try to DNS lookup the hostname, when it can
>> not find it via DNS then it look up in /etc/hosts?
> 
> On Darwin I believe that by default we pass DNS lookups to the C
> library.  So I think that what you are seeing is the behavior of the C
> library.  Try setting the environment variable GODEBUG=netdns=go.
> 
> Ian
> 
> 
>> On 2/22/21, Ian Lance Taylor  wrote:
>>> On Mon, Feb 22, 2021 at 12:22 PM Peng Yu  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
>>> 
>> 
>> 
>> --
>> Regards,
>> Peng
> 
> -- 
> 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 golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/CAOyqgcUSpK7sVTcz8-Yy83rGuatMrOn4qqFNA_205_bdUy6taQ%40mail.gmail.com
>  
> .

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/78080E79-9B29-42F1-9627-9F8FC16FAA88%40ix.netcom.com.


Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-22 Thread Ian Lance Taylor
On Mon, Feb 22, 2021 at 9:11 PM Peng Yu  wrote:
>
> I tried 1.16.
>
> $ go version
> go version go1.16 darwin/amd64
>
> The problem still exists. When I change mymachine.local to
> mymachine_local, the problem is gone. So somehow, this is related to
> host resolution? It might try to DNS lookup the hostname, when it can
> not find it via DNS then it look up in /etc/hosts?

On Darwin I believe that by default we pass DNS lookups to the C
library.  So I think that what you are seeing is the behavior of the C
library.  Try setting the environment variable GODEBUG=netdns=go.

Ian


> On 2/22/21, Ian Lance Taylor  wrote:
> > On Mon, Feb 22, 2021 at 12:22 PM Peng Yu  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
> >
>
>
> --
> Regards,
> Peng

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcUSpK7sVTcz8-Yy83rGuatMrOn4qqFNA_205_bdUy6taQ%40mail.gmail.com.


Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-22 Thread Shulhan



> On 23 Feb 2021, at 12.11, Peng Yu  wrote:
> 
> I tried 1.16.
> 
> $ go version
> go version go1.16 darwin/amd64
> 
> The problem still exists. When I change mymachine.local to
> mymachine_local, the problem is gone. So somehow, this is related to
> host resolution? It might try to DNS lookup the hostname, when it can
> not find it via DNS then it look up in /etc/hosts?

I see that you run macOS.  In the macOS, the local TLD is resolved using 
multicast DNS. You can try search for "macos local TLD".

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/B013250D-8C94-47F4-912A-A42F32E6DC61%40gmail.com.


Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-22 Thread Peng Yu
I tried 1.16.

$ go version
go version go1.16 darwin/amd64

The problem still exists. When I change mymachine.local to
mymachine_local, the problem is gone. So somehow, this is related to
host resolution? It might try to DNS lookup the hostname, when it can
not find it via DNS then it look up in /etc/hosts?

On 2/22/21, Ian Lance Taylor  wrote:
> On Mon, Feb 22, 2021 at 12:22 PM Peng Yu  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
>


-- 
Regards,
Peng

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CABrM6wkj52WUD-ozY%3Djt2mnGXTpYf0wTmRNmLi18OfbA2hccdg%40mail.gmail.com.


Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-22 Thread Ian Lance Taylor
On Mon, Feb 22, 2021 at 12:22 PM Peng Yu  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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcWQvAH5yVytaPkPLhh%3DJ5x9Hh4GD-d4O2tKURC699gA1A%40mail.gmail.com.


[go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-22 Thread Peng Yu
Hi,

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)
  }
}

-- 
Regards,
Peng

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CABrM6w%3DavxDHaK%2BOu_KaSdKmvpWhERyfLSoUL0q_UtowbD-%3DEg%40mail.gmail.com.