From: Russ Cox Date: Wed, 11 Sep 2013 15:38:56 +0000 (-0400) Subject: net: defend against broken getaddrinfo on Linux X-Git-Tag: go1.2rc2~262 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=382738af513a5390620b55a84b9e14f3afd0128e;p=gostls13.git net: defend against broken getaddrinfo on Linux getaddrinfo is supposed to set errno when it returns EAI_SYSTEM, but sometimes it does not. Fixes #6232. R=golang-dev, iant CC=golang-dev https://golang.org/cl/13532045 --- diff --git a/src/pkg/net/cgo_unix.go b/src/pkg/net/cgo_unix.go index 1d736257f5..8397cd70c2 100644 --- a/src/pkg/net/cgo_unix.go +++ b/src/pkg/net/cgo_unix.go @@ -99,6 +99,16 @@ func cgoLookupIPCNAME(name string) (addrs []IP, cname string, err error, complet if gerrno == C.EAI_NONAME { str = noSuchHost } else if gerrno == C.EAI_SYSTEM { + if err == nil { + // err should not be nil, but sometimes getaddrinfo returns + // gerrno == C.EAI_SYSTEM with err == nil on Linux. + // The report claims that it happens when we have too many + // open files, so use syscall.EMFILE (too many open files in system). + // Most system calls would return ENFILE (too many open files), + // so at the least EMFILE should be easy to recognize if this + // comes up again. golang.org/issue/6232. + err = syscall.EMFILE + } str = err.Error() } else { str = C.GoString(C.gai_strerror(gerrno))