From 152d806b169a54564a21fd91d5cd3fb3cee1a5dc Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Tue, 21 Feb 2012 16:48:05 +1100 Subject: [PATCH] net: extend the workaround to DialTCP to try to get arm building again. Awfulness by the bucket that we hope Fixes #3057. R=golang-dev, mikioh.mikioh, dsymonds, r, rsc CC=golang-dev https://golang.org/cl/5687060 --- src/pkg/net/ipsock_posix.go | 4 ---- src/pkg/net/tcpsock_posix.go | 22 ++++++++++++---------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/pkg/net/ipsock_posix.go b/src/pkg/net/ipsock_posix.go index 8754451b33e..4da18a5061a 100644 --- a/src/pkg/net/ipsock_posix.go +++ b/src/pkg/net/ipsock_posix.go @@ -117,10 +117,6 @@ func internetSocket(net string, laddr, raddr sockaddr, sotype, proto int, mode s if ra, oserr = raddr.sockaddr(family); oserr != nil { goto Error } - if ra == nil { - // TODO(r): part of selfConnect debugging - panic("ra nil when raddr non-nil") - } } fd, oserr = socket(net, family, sotype, proto, la, ra, toAddr) if oserr != nil { diff --git a/src/pkg/net/tcpsock_posix.go b/src/pkg/net/tcpsock_posix.go index 1280f7bb08b..e05bc10170e 100644 --- a/src/pkg/net/tcpsock_posix.go +++ b/src/pkg/net/tcpsock_posix.go @@ -29,8 +29,7 @@ func sockaddrToTCP(sa syscall.Sockaddr) Addr { return &TCPAddr{sa.Addr[0:], sa.Port} default: if sa != nil { - // TODO(r): Diagnose when we will turn a non-nil sockaddr into a nil. - // Part of diagnosing the selfConnect bug. + // Diagnose when we will turn a non-nil sockaddr into a nil. panic(fmt.Sprintf("unexpected type in sockaddrToTCP: %T", sa)) } } @@ -237,13 +236,6 @@ func DialTCP(net string, laddr, raddr *TCPAddr) (*TCPConn, error) { fd, err := internetSocket(net, laddr.toAddr(), raddr.toAddr(), syscall.SOCK_STREAM, 0, "dial", sockaddrToTCP) - checkRaddr := func(s string) { - if err == nil && fd.raddr == nil { - panic("nil raddr in DialTCP: " + s) - } - } - checkRaddr("early") - // TCP has a rarely used mechanism called a 'simultaneous connection' in // which Dial("tcp", addr1, addr2) run on the machine at addr1 can // connect to a simultaneous Dial("tcp", addr2, addr1) run on the machine @@ -264,7 +256,6 @@ func DialTCP(net string, laddr, raddr *TCPAddr) (*TCPConn, error) { for i := 0; i < 2 && err == nil && laddr == nil && selfConnect(fd); i++ { fd.Close() fd, err = internetSocket(net, laddr.toAddr(), raddr.toAddr(), syscall.SOCK_STREAM, 0, "dial", sockaddrToTCP) - checkRaddr("after close") } if err != nil { @@ -274,6 +265,17 @@ func DialTCP(net string, laddr, raddr *TCPAddr) (*TCPConn, error) { } func selfConnect(fd *netFD) bool { + // The socket constructor can return an fd with raddr nil under certain + // unknown conditions. The errors in the calls there to Getpeername + // are discarded, but we can't catch the problem there because those + // calls are sometimes legally erroneous with a "socket not connected". + // Since this code (selfConnect) is already trying to work around + // a problem, we make sure if this happens we recognize trouble and + // ask the DialTCP routine to try again. + // TODO: try to understand what's really going on. + if fd.laddr == nil || fd.raddr == nil { + return true + } l := fd.laddr.(*TCPAddr) r := fd.raddr.(*TCPAddr) return l.Port == r.Port && l.IP.Equal(r.IP)