From 2ba63a85c10c950389be2d3a17619cd6782df691 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Mon, 6 Mar 2023 10:33:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9C=A8=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E8=AF=BB=E5=86=99=E4=BC=98=E5=8C=96=E6=A8=A1=E5=BC=8F=E4=B8=8B?= =?UTF-8?q?fastcgi=E6=97=A0=E6=B3=95=E6=AD=A3=E5=B8=B8=E5=B7=A5=E4=BD=9C?= =?UTF-8?q?=E7=9A=84Bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/client_conn.go | 6 +++--- internal/nodes/client_conn_base.go | 6 +++--- internal/nodes/client_conn_interface.go | 4 ++-- internal/nodes/client_tls_conn.go | 4 ++-- internal/nodes/http_request_fastcgi.go | 10 ++++++++++ internal/nodes/http_request_websocket.go | 2 +- 6 files changed, 21 insertions(+), 11 deletions(-) diff --git a/internal/nodes/client_conn.go b/internal/nodes/client_conn.go index 369dd8b..767de82 100644 --- a/internal/nodes/client_conn.go +++ b/internal/nodes/client_conn.go @@ -105,7 +105,7 @@ func (this *ClientConn) Read(b []byte) (n int, err error) { } // 设置读超时时间 - if this.isHTTP && !this.isWebsocket && !this.isShortReading && this.autoReadTimeout { + if this.isHTTP && !this.isPersistent && !this.isShortReading && this.autoReadTimeout { this.setHTTPReadTimeout() } @@ -172,7 +172,7 @@ func (this *ClientConn) Write(b []byte) (n int, err error) { } // 延长读超时时间 - if this.isHTTP && !this.isWebsocket && this.autoReadTimeout { + if this.isHTTP && !this.isPersistent && this.autoReadTimeout { this.setHTTPReadTimeout() } @@ -238,7 +238,7 @@ func (this *ClientConn) SetDeadline(t time.Time) error { func (this *ClientConn) SetReadDeadline(t time.Time) error { // 如果开启了HTTP自动读超时选项,则自动控制超时时间 - if this.isHTTP && !this.isWebsocket && this.autoReadTimeout { + if this.isHTTP && !this.isPersistent && this.autoReadTimeout { this.isShortReading = false var unixTime = t.Unix() diff --git a/internal/nodes/client_conn_base.go b/internal/nodes/client_conn_base.go index 62a0c87..3473a2a 100644 --- a/internal/nodes/client_conn_base.go +++ b/internal/nodes/client_conn_base.go @@ -16,7 +16,7 @@ type BaseClientConn struct { remoteAddr string hasLimit bool - isWebsocket bool + isPersistent bool // 是否为持久化连接 isClosed bool @@ -125,6 +125,6 @@ func (this *BaseClientConn) SetLinger(seconds int) error { return nil } -func (this *BaseClientConn) SetIsWebsocket(isWebsocket bool) { - this.isWebsocket = isWebsocket +func (this *BaseClientConn) SetIsPersistent(isPersistent bool) { + this.isPersistent = isPersistent } diff --git a/internal/nodes/client_conn_interface.go b/internal/nodes/client_conn_interface.go index 72a25b9..8026554 100644 --- a/internal/nodes/client_conn_interface.go +++ b/internal/nodes/client_conn_interface.go @@ -24,6 +24,6 @@ type ClientConnInterface interface { // UserId 获取当前连接所属服务的用户ID UserId() int64 - // SetIsWebsocket 设置是否为Websocket - SetIsWebsocket(isWebsocket bool) + // SetIsPersistent 设置是否为持久化 + SetIsPersistent(isPersistent bool) } diff --git a/internal/nodes/client_tls_conn.go b/internal/nodes/client_tls_conn.go index e5b7d18..69335d9 100644 --- a/internal/nodes/client_tls_conn.go +++ b/internal/nodes/client_tls_conn.go @@ -56,14 +56,14 @@ func (this *ClientTLSConn) SetWriteDeadline(t time.Time) error { return this.rawConn.SetWriteDeadline(t) } -func (this *ClientTLSConn) SetIsWebsocket(isWebsocket bool) { +func (this *ClientTLSConn) SetIsPersistent(isPersistent bool) { tlsConn, ok := this.rawConn.(*tls.Conn) if ok { var rawConn = tlsConn.NetConn() if rawConn != nil { clientConn, ok := rawConn.(*ClientConn) if ok { - clientConn.SetIsWebsocket(isWebsocket) + clientConn.SetIsPersistent(isPersistent) } } } diff --git a/internal/nodes/http_request_fastcgi.go b/internal/nodes/http_request_fastcgi.go index 520af44..325249f 100644 --- a/internal/nodes/http_request_fastcgi.go +++ b/internal/nodes/http_request_fastcgi.go @@ -73,6 +73,16 @@ func (this *HTTPRequest) doFastcgi() (shouldStop bool) { } } + // 设置为持久化连接 + var requestConn = this.RawReq.Context().Value(HTTPConnContextKey) + if requestConn == nil { + return + } + requestClientConn, ok := requestConn.(ClientConnInterface) + if ok { + requestClientConn.SetIsPersistent(true) + } + // 连接池配置 poolSize := fastcgi.PoolSize if poolSize <= 0 { diff --git a/internal/nodes/http_request_websocket.go b/internal/nodes/http_request_websocket.go index ea04f7f..014e2e9 100644 --- a/internal/nodes/http_request_websocket.go +++ b/internal/nodes/http_request_websocket.go @@ -111,7 +111,7 @@ func (this *HTTPRequest) doWebsocket(requestHost string, isLastRetry bool) (shou requestClientConn, ok := requestConn.(ClientConnInterface) if ok { - requestClientConn.SetIsWebsocket(true) + requestClientConn.SetIsPersistent(true) } clientConn, _, err := this.writer.Hijack()