From 382738af513a5390620b55a84b9e14f3afd0128e Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 11 Sep 2013 11:38:56 -0400 Subject: [PATCH] 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 --- src/pkg/net/cgo_unix.go | 10 ++++++++++ 1 file changed, 10 insertions(+) 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)) -- 2.50.0