From d5de8e27cc8e1fb0754c6307683de6f54441a541 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Mon, 25 Feb 2019 10:22:04 +0100 Subject: [PATCH] slow down when there is not enough file descriptors. fixes #1574 --- transport/internet/tcp/hub.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/transport/internet/tcp/hub.go b/transport/internet/tcp/hub.go index 15515961..f3e6ade0 100644 --- a/transport/internet/tcp/hub.go +++ b/transport/internet/tcp/hub.go @@ -6,6 +6,7 @@ import ( "context" gotls "crypto/tls" "strings" + "time" "v2ray.com/core/common" "v2ray.com/core/common/net" @@ -64,10 +65,14 @@ func (v *Listener) keepAccepting() { for { conn, err := v.listener.Accept() if err != nil { - if strings.Contains(err.Error(), "closed") { + errStr := err.Error() + if strings.Contains(errStr, "closed") { break } newError("failed to accepted raw connections").Base(err).AtWarning().WriteToLog() + if strings.Contains(errStr, "too many") { + time.Sleep(time.Millisecond * 500) + } continue }