mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 06:27:05 +00:00
Merge pull request #6737 from xiang90/p_tcp
pkg/proxy: a more reliable way to detect a closed proxy
This commit is contained in:
commit
96bcb56f10
@ -94,19 +94,22 @@ func (tcp *tcpProxySocket) ProxyLoop(service ServicePortName, myInfo *serviceInf
|
|||||||
for {
|
for {
|
||||||
if info, exists := proxier.getServiceInfo(service); !exists || info != myInfo {
|
if info, exists := proxier.getServiceInfo(service); !exists || info != myInfo {
|
||||||
// The service port was closed or replaced.
|
// The service port was closed or replaced.
|
||||||
break
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Block until a connection is made.
|
// Block until a connection is made.
|
||||||
inConn, err := tcp.Accept()
|
inConn, err := tcp.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if info, exists := proxier.getServiceInfo(service); !exists || info != myInfo {
|
|
||||||
// Then the service port was just closed so the accept failure is to be expected.
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if isTooManyFDsError(err) {
|
if isTooManyFDsError(err) {
|
||||||
panic("Accept failed: " + err.Error())
|
panic("Accept failed: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if isClosedError(err) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if info, exists := proxier.getServiceInfo(service); !exists || info != myInfo {
|
||||||
|
// Then the service port was just closed so the accept failure is to be expected.
|
||||||
|
return
|
||||||
|
}
|
||||||
glog.Errorf("Accept failed: %v", err)
|
glog.Errorf("Accept failed: %v", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -801,3 +804,10 @@ func (proxier *Proxier) iptablesHostPortalArgs(destIP net.IP, destPort int, prot
|
|||||||
func isTooManyFDsError(err error) bool {
|
func isTooManyFDsError(err error) bool {
|
||||||
return strings.Contains(err.Error(), "too many open files")
|
return strings.Contains(err.Error(), "too many open files")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isClosedError(err error) bool {
|
||||||
|
// A brief discussion about handling closed error here:
|
||||||
|
// https://code.google.com/p/go/issues/detail?id=4373#c14
|
||||||
|
// TODO: maybe create a stoppable TCP listener that returns a StoppedError
|
||||||
|
return strings.HasSuffix(err.Error(), "use of closed network connection")
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user