Skip to content

Commit 382738a

Browse files
committed
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
1 parent 397ba2c commit 382738a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/pkg/net/cgo_unix.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ func cgoLookupIPCNAME(name string) (addrs []IP, cname string, err error, complet
9999
if gerrno == C.EAI_NONAME {
100100
str = noSuchHost
101101
} else if gerrno == C.EAI_SYSTEM {
102+
if err == nil {
103+
// err should not be nil, but sometimes getaddrinfo returns
104+
// gerrno == C.EAI_SYSTEM with err == nil on Linux.
105+
// The report claims that it happens when we have too many
106+
// open files, so use syscall.EMFILE (too many open files in system).
107+
// Most system calls would return ENFILE (too many open files),
108+
// so at the least EMFILE should be easy to recognize if this
109+
// comes up again. golang.org/issue/6232.
110+
err = syscall.EMFILE
111+
}
102112
str = err.Error()
103113
} else {
104114
str = C.GoString(C.gai_strerror(gerrno))

0 commit comments

Comments
 (0)