From 4b299476521d80c7e071d5551b22555638d6d7f3 Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Sat, 11 Apr 2015 08:46:44 -0700 Subject: [PATCH] pkg/proxy: panic if run out of fd When proxy runs out of fd, it fills the logs with error message. From #6716, it is better to just panic(). --- pkg/proxy/proxier.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/proxy/proxier.go b/pkg/proxy/proxier.go index d297e3392ee..c66d14c74d7 100644 --- a/pkg/proxy/proxier.go +++ b/pkg/proxy/proxier.go @@ -79,6 +79,9 @@ func tryConnect(service ServicePortName, srcAddr net.Addr, protocol string, prox // and keep accepting inbound traffic. outConn, err := net.DialTimeout(protocol, endpoint, retryTimeout*time.Second) if err != nil { + if isTooManyFDsError(err) { + panic("Dial failed: " + err.Error()) + } glog.Errorf("Dial failed: %v", err) continue } @@ -101,6 +104,9 @@ func (tcp *tcpProxySocket) ProxyLoop(service ServicePortName, myInfo *serviceInf // Then the service port was just closed so the accept failure is to be expected. break } + if isTooManyFDsError(err) { + panic("Accept failed: " + err.Error()) + } glog.Errorf("Accept failed: %v", err) continue } @@ -791,3 +797,7 @@ func (proxier *Proxier) iptablesHostPortalArgs(destIP net.IP, destPort int, prot args = append(args, "-j", "DNAT", "--to-destination", net.JoinHostPort(proxyIP.String(), strconv.Itoa(proxyPort))) return args } + +func isTooManyFDsError(err error) bool { + return strings.Contains(err.Error(), "too many open files") +}