From a0cfaa9fa68a8de42d3274ef22df0fbb7793dc07 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Mon, 12 Dec 2022 10:04:36 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=85=A2=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E8=B6=85=E6=97=B6=E7=AE=97=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/client_conn.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/nodes/client_conn.go b/internal/nodes/client_conn.go index 678452f..a63d53f 100644 --- a/internal/nodes/client_conn.go +++ b/internal/nodes/client_conn.go @@ -115,7 +115,11 @@ func (this *ClientConn) Read(b []byte) (n int, err error) { func (this *ClientConn) Write(b []byte) (n int, err error) { // 设置超时时间 - _ = this.rawConn.SetWriteDeadline(time.Now().Add(60 * time.Second)) // TODO 时间可以设置 + var timeoutSeconds = len(b) / 512 + if timeoutSeconds < 5 { + timeoutSeconds = 5 + } + _ = this.rawConn.SetWriteDeadline(time.Now().Add(time.Duration(timeoutSeconds) * time.Second)) // TODO 时间可以设置 n, err = this.rawConn.Write(b) if n > 0 { @@ -130,6 +134,7 @@ func (this *ClientConn) Write(b []byte) (n int, err error) { // 如果是写入超时,则立即关闭连接 if err != nil && os.IsTimeout(err) { + // TODO 考虑对多次慢连接的IP做出惩罚 conn, ok := this.rawConn.(LingerConn) if ok { _ = conn.SetLinger(0)