udp timeout on MacOS X

349 views
Skip to first unread message

Miek Gieben

unread,
Jan 24, 2012, 3:42:14 AM1/24/12
to Go list
Hello,

For the Go DNS [*] package I create some example programs one
of which is called 'q' [**]. This acts the same of the dns
query tool 'dig' which you may have heard of.

'q' basically opens an udp port, sends a query and waits for
the reply. This all works correct on Ubuntu with the lastest
weekly. On mac OS X I keep getting reports about i/o timeouts.
For tcp connection both Ubuntu and mac OS X work fine.

I don't own a machine with mac OS X, could someone with such
software double check? 'q @open.nlnetlabs.nl MX miek.nl' should
give such a timeout.

[*]
https://github.com/miekg/godns

[**]
http://www.miek.nl/blog/archives/2012/01/23/super-short_guide_to_getting_q/index.html

grtz,

--
Miek

signature.asc

Dave Cheney

unread,
Jan 24, 2012, 3:50:22 AM1/24/12
to Go list
darwin/amd64 lion 10.7.2

odessa(~/devel/godns/examples/q) % ./q @open.nlnetlabs.nl MX miek.nl
read udp 192.168.1.129:62764: i/o timeout

Miek Gieben

unread,
Jan 24, 2012, 3:55:00 AM1/24/12
to Go list
[ Quoting <da...@cheney.net> at 19:50 on Jan 24 in "Re: [go-nuts] udp ti..." ]

> darwin/amd64 lion 10.7.2
>
> odessa(~/devel/godns/examples/q) % ./q @open.nlnetlabs.nl MX miek.nl
> read udp 192.168.1.129:62764: i/o timeout

Thanks for the quick test :-)

Ok, now what? It works on Ubuntu, and I do believe I'm using the
new SetDeadline stuff OK.

I will try to skim through the net's dns*.go files to see what happens
there.

grtz Miek

signature.asc

Yves Junqueira

unread,
Jan 24, 2012, 5:22:45 AM1/24/12
to Go list

Sorry if i cant't be more precise right now, but there were changes to socket default settings in various platforms - this may be affecting you. Look for recent changes to the net package by Mikio Hara (IIRC), that might give you some light.

(phone)

Mikio Hara

unread,
Jan 24, 2012, 7:36:32 AM1/24/12
to golan...@googlegroups.com
Yikes!

On Tue, Jan 24, 2012 at 7:22 PM, Yves Junqueira
<yves.ju...@gmail.com> wrote:

> Sorry if i cant't be more precise right now, but there were changes to
> socket default settings in various platforms - this may be affecting you.
> Look for recent changes to the net package by Mikio Hara (IIRC), that might
> give you some light.

Looks like all BSD variants have same problem.
I just tried mx: "dtruss ./mx golang.org" on both darwin and freebsd,
got same error EISCONN, strange.

socket(0x2, 0x2, 0x0) = 7 0
fcntl(0x7, 0x2, 0x1) = 0 0
setsockopt(0x7, 0xFFFF, 0x20) = 0 0 // set socket to SO_BROADCAST
fcntl(0x7, 0x3, 0x0) = 2 0
fcntl(0x7, 0x4, 0x6) = 0 0
connect(0x7, 0xF8400026A8, 0x10) = 0 0
getsockname(0x7, 0xF840000C40, 0xF840011150) = 0 0
getpeername(0x7, 0xF840000BD0, 0xF840011158) = 0 0
gettimeofday(0x22BFAC8, 0x0, 0x22BFD38) = 1327408294 0
gettimeofday(0x22BFAC8, 0x0, 0x2) = 1327408294 0
sendto(0x7, 0xF84001DFC0, 0x1C) = -1 Err#56
shutdown(0x7, 0x2, 0x0) = 0 0
fcntl(0x7, 0x3, 0x0) = 6 0
fcntl(0x7, 0x4, 0x2) = 0 0
close(0x7) = 0 0
write(0x1, "write udp 192.168.12.1:53: socket is already
connected\n\0", 0x37) = 55 0

Miek Gieben

unread,
Jan 24, 2012, 8:19:41 AM1/24/12
to golan...@googlegroups.com
[ Quoting <mikioh...@gmail.com> at 21:36 on Jan 24 in "Re: [go-nuts] udp ti..." ]
> Yikes!

>
> Looks like all BSD variants have same problem.
> I just tried mx: "dtruss ./mx golang.org" on both darwin and freebsd,
> got same error EISCONN, strange.
>

<SNIP>

> fcntl(0x7, 0x4, 0x2) = 0 0
> close(0x7) = 0 0
> write(0x1, "write udp 192.168.12.1:53: socket is already connected\n\0", 0x37) = 55 0

But is this my fault (as in: my Go code is wrong)? Or is this something deep in
Go?

grtz,

--
Miek

signature.asc

Mikio Hara

unread,
Jan 24, 2012, 9:51:18 AM1/24/12
to golan...@googlegroups.com
On Tue, Jan 24, 2012 at 10:19 PM, Miek Gieben <mi...@miek.nl> wrote:

> But is this my fault (as in: my Go code is wrong)? Or is this something deep in
> Go?

Ah, hard to say.
Here is a result of toy experiment on socket stuff
with attached source code.

Darwin:
2012/01/24 23:46:05 WriteTo with CO socket: darwin write udp
8.8.8.8:53: socket is already connected
2012/01/24 23:46:05 Write with CL socket: darwin write udp:
destination address required

FreeBSD:
2012/01/24 23:46:51 WriteTo with CO socket: freebsd write udp
8.8.8.8:53: socket is already connected
2012/01/24 23:46:51 Write with CL socket: freebsd write udp:
destination address required

Linux:
2012/01/24 23:46:11 Write with CL socket: linux write udp: destination
address required

--
package main

import (
"log"
"net"
"runtime"
)

func main() {
la := &net.UDPAddr{} // wildcard
ra, err := net.ResolveUDPAddr("udp", "8.8.8.8:53")
if err != nil {
log.Fatal(err)
}

c, err := net.DialUDP("udp", nil, ra)
if err != nil {
log.Fatal(err)
}
_, err = c.WriteTo([]byte("ABCD"), ra)
if err != nil {
log.Println("WriteTo with CO socket:", runtime.GOOS, err)
}
_, err = c.Write([]byte("ABCD"))
if err != nil {
log.Println("Write with CO socket:", runtime.GOOS, err)
}

l, err := net.ListenUDP("udp", la)
if err != nil {
log.Fatal(err)
}
_, err = l.WriteTo([]byte("ABCD"), ra)
if err != nil {
log.Println("WriteTo with CL socket:", runtime.GOOS, err)
}
_, err = l.Write([]byte("ABCD"))
if err != nil {
log.Println("Write with CL socket:", runtime.GOOS, err)
}
}

Brad Fitzpatrick

unread,
Jan 24, 2012, 9:53:16 AM1/24/12
to Mikio Hara, golan...@googlegroups.com
Please file a bug if you haven't already.

Mikio Hara

unread,
Jan 24, 2012, 10:09:47 AM1/24/12
to Brad Fitzpatrick, golan...@googlegroups.com
On Tue, Jan 24, 2012 at 11:53 PM, Brad Fitzpatrick <brad...@golang.org> wrote:

> Please file a bug if you haven't already.

Some supplementary:

Seems like sendto with connection-oriented mode socket
on Linux can ignore or override pre-specified address.
That's the reason why godns apps work on Linux.

Returning error on write with connection-less mode socket
seems correct behavior.

Mikio Hara

unread,
Jan 24, 2012, 12:48:54 PM1/24/12
to golan...@googlegroups.com
Hi Miek,

On Tue, Jan 24, 2012 at 10:19 PM, Miek Gieben <mi...@miek.nl> wrote:

> But is this my fault (as in: my Go code is wrong)? Or is this something deep in
> Go?

Filed issue 2773.

Reply all
Reply to author
Forward
0 new messages