diff --git a/internal/nodes/client_conn.go b/internal/nodes/client_conn.go index eb4a87c..b0e58f3 100644 --- a/internal/nodes/client_conn.go +++ b/internal/nodes/client_conn.go @@ -86,18 +86,21 @@ func (this *ClientConn) Read(b []byte) (n int, err error) { } } - // SYN Flood检测 var isHandshakeError = err != nil && os.IsTimeout(err) && !this.hasRead if isHandshakeError { _ = this.SetLinger(0) } - var synFloodConfig = sharedNodeConfig.SYNFloodConfig() - if synFloodConfig != nil && synFloodConfig.IsOn { - if isHandshakeError { - this.increaseSYNFlood(synFloodConfig) - } else if err == nil && !this.hasResetSYNFlood { - this.hasResetSYNFlood = true - this.resetSYNFlood() + + // SYN Flood检测 + if this.serverId == 0 || !this.hasResetSYNFlood { + var synFloodConfig = sharedNodeConfig.SYNFloodConfig() + if synFloodConfig != nil && synFloodConfig.IsOn { + if isHandshakeError { + this.increaseSYNFlood(synFloodConfig) + } else if err == nil && !this.hasResetSYNFlood { + this.hasResetSYNFlood = true + this.resetSYNFlood() + } } } @@ -126,7 +129,9 @@ func (this *ClientConn) Close() error { err := this.rawConn.Close() // 单个服务并发数限制 - sharedClientConnLimiter.Remove(this.rawConn.RemoteAddr().String()) + if this.hasLimit { + sharedClientConnLimiter.Remove(this.rawConn.RemoteAddr().String()) + } return err } diff --git a/internal/nodes/client_conn_base.go b/internal/nodes/client_conn_base.go index 93b8dd0..fc8f6b6 100644 --- a/internal/nodes/client_conn_base.go +++ b/internal/nodes/client_conn_base.go @@ -11,6 +11,7 @@ type BaseClientConn struct { userId int64 serverId int64 remoteAddr string + hasLimit bool isClosed bool } @@ -32,6 +33,7 @@ func (this *BaseClientConn) Bind(serverId int64, remoteAddr string, maxConnsPerS this.isBound = true this.serverId = serverId this.remoteAddr = remoteAddr + this.hasLimit = true // 检查是否可以连接 return sharedClientConnLimiter.Add(this.rawConn.RemoteAddr().String(), serverId, remoteAddr, maxConnsPerServer, maxConnsPerIP) diff --git a/internal/nodes/http_request_reverse_proxy.go b/internal/nodes/http_request_reverse_proxy.go index 9c6796c..75b2f3f 100644 --- a/internal/nodes/http_request_reverse_proxy.go +++ b/internal/nodes/http_request_reverse_proxy.go @@ -78,7 +78,7 @@ func (this *HTTPRequest) doReverseProxy() { // 处理Scheme if origin.Addr == nil { - err := errors.New(this.URL() + ": origin '" + strconv.FormatInt(origin.Id, 10) + "' does not has a address") + err := errors.New(this.URL() + ": Origin '" + strconv.FormatInt(origin.Id, 10) + "' does not has a address") remotelogs.Error("HTTP_REQUEST_REVERSE_PROXY", err.Error()) this.write50x(err, http.StatusBadGateway, true) return @@ -130,7 +130,7 @@ func (this *HTTPRequest) doReverseProxy() { if origin.FollowPort { var originHostIndex = strings.Index(originAddr, ":") if originHostIndex < 0 { - var originErr = errors.New("invalid origin address '" + originAddr + "', lacking port") + var originErr = errors.New(this.URL() + ": Invalid origin address '" + originAddr + "', lacking port") remotelogs.Error("HTTP_REQUEST_REVERSE_PROXY", originErr.Error()) this.write50x(originErr, http.StatusBadGateway, true) return @@ -210,7 +210,7 @@ func (this *HTTPRequest) doReverseProxy() { // 获取请求客户端 client, err := SharedHTTPClientPool.Client(this, origin, originAddr, this.reverseProxy.ProxyProtocol, this.reverseProxy.FollowRedirects) if err != nil { - remotelogs.Error("HTTP_REQUEST_REVERSE_PROXY", this.URL()+": get client failed: "+err.Error()) + remotelogs.Error("HTTP_REQUEST_REVERSE_PROXY", this.URL()+": Create client failed: "+err.Error()) this.write50x(err, http.StatusBadGateway, true) return } @@ -231,7 +231,7 @@ func (this *HTTPRequest) doReverseProxy() { this.reverseProxy.ResetScheduling() }) this.write50x(err, http.StatusBadGateway, true) - remotelogs.Warn("HTTP_REQUEST_REVERSE_PROXY", this.RawReq.URL.String()+"': request failed: "+err.Error()) + remotelogs.Warn("HTTP_REQUEST_REVERSE_PROXY", this.RawReq.URL.String()+": Request origin server failed: "+err.Error()) } else if httpErr.Err != context.Canceled { SharedOriginStateManager.Fail(origin, requestHost, this.reverseProxy, func() { this.reverseProxy.ResetScheduling() @@ -244,7 +244,7 @@ func (this *HTTPRequest) doReverseProxy() { this.write50x(err, http.StatusBadGateway, true) } if httpErr.Err != io.EOF { - remotelogs.Warn("HTTP_REQUEST_REVERSE_PROXY", this.URL()+": request failed: "+err.Error()) + remotelogs.Warn("HTTP_REQUEST_REVERSE_PROXY", this.URL()+": Request origin server failed: "+err.Error()) } } else { // 是否为客户端方面的错误 @@ -283,7 +283,7 @@ func (this *HTTPRequest) doReverseProxy() { if this.doWAFResponse(resp) { err = resp.Body.Close() if err != nil { - remotelogs.Warn("HTTP_REQUEST_REVERSE_PROXY", this.URL()+": "+err.Error()) + remotelogs.Warn("HTTP_REQUEST_REVERSE_PROXY", this.URL()+": Closing Error (WAF): "+err.Error()) } return } @@ -293,7 +293,7 @@ func (this *HTTPRequest) doReverseProxy() { if len(this.web.Pages) > 0 && this.doPage(resp.StatusCode) { err = resp.Body.Close() if err != nil { - remotelogs.Warn("HTTP_REQUEST_REVERSE_PROXY", this.URL()+": "+err.Error()) + remotelogs.Warn("HTTP_REQUEST_REVERSE_PROXY", this.URL()+": Closing error (Page): "+err.Error()) } return } @@ -395,13 +395,13 @@ func (this *HTTPRequest) doReverseProxy() { var closeErr = resp.Body.Close() if closeErr != nil { if !this.canIgnore(closeErr) { - remotelogs.Warn("HTTP_REQUEST_REVERSE_PROXY", this.URL()+": closing error: "+closeErr.Error()) + remotelogs.Warn("HTTP_REQUEST_REVERSE_PROXY", this.URL()+": Closing error: "+closeErr.Error()) } } if err != nil && err != io.EOF { if !this.canIgnore(err) { - remotelogs.Warn("HTTP_REQUEST_REVERSE_PROXY", this.URL()+": writing error: "+err.Error()) + remotelogs.Warn("HTTP_REQUEST_REVERSE_PROXY", this.URL()+": Writing error: "+err.Error()) this.addError(err) } }