From 43373da712734767adbb3037837700e54bd35580 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Thu, 13 Jan 2022 11:45:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/client_conn.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/internal/nodes/client_conn.go b/internal/nodes/client_conn.go index e357754..081a778 100644 --- a/internal/nodes/client_conn.go +++ b/internal/nodes/client_conn.go @@ -24,9 +24,10 @@ type ClientConn struct { once sync.Once globalLimiter *ratelimit.Counter - isTLS bool - hasDeadline bool - hasRead bool + isTLS bool + hasDeadline bool + hasRead bool + hasResetSYNFlood bool BaseClientConn @@ -59,22 +60,24 @@ func (this *ClientConn) Read(b []byte) (n int, err error) { n, err = this.rawConn.Read(b) if n > 0 { atomic.AddUint64(&teaconst.InTrafficBytes, uint64(n)) - this.hasRead = true + if !this.hasRead { + this.hasRead = true + } } // SYN Flood检测 + var isHandshakeError = err != nil && os.IsTimeout(err) && !this.hasRead var synFloodConfig = sharedNodeConfig.SYNFloodConfig() if synFloodConfig != nil && synFloodConfig.IsOn { - if err != nil && os.IsTimeout(err) { + if isHandshakeError { _ = this.SetLinger(0) - - if !this.hasRead { - this.increaseSYNFlood(synFloodConfig) - } + this.increaseSYNFlood(synFloodConfig) } else if err == nil && !this.hasResetSYNFlood { this.hasResetSYNFlood = true this.resetSYNFlood() } + } else if isHandshakeError { + _ = this.SetLinger(0) } return