From ade979a72560b9ac2e09eb3c3c86880e8559fae4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Sat, 10 Dec 2022 19:51:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=91=E5=AE=A2=E6=88=B7=E7=AB=AF=E5=86=99?= =?UTF-8?q?=E5=85=A5=E6=95=B0=E6=8D=AE=E8=B6=85=E6=97=B6=E6=97=B6=E7=AB=8B?= =?UTF-8?q?=E5=8D=B3=E5=85=B3=E9=97=AD=E8=BF=9E=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/client_conn.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/nodes/client_conn.go b/internal/nodes/client_conn.go index d7f10c2..678452f 100644 --- a/internal/nodes/client_conn.go +++ b/internal/nodes/client_conn.go @@ -115,7 +115,7 @@ 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(30 * time.Second)) // TODO 时间可以设置 + _ = this.rawConn.SetWriteDeadline(time.Now().Add(60 * time.Second)) // TODO 时间可以设置 n, err = this.rawConn.Write(b) if n > 0 { @@ -128,6 +128,14 @@ func (this *ClientConn) Write(b []byte) (n int, err error) { } } + // 如果是写入超时,则立即关闭连接 + if err != nil && os.IsTimeout(err) { + conn, ok := this.rawConn.(LingerConn) + if ok { + _ = conn.SetLinger(0) + } + } + return }