From 1fc2a92f2b18d6aad5b8245bf8cd32b18ddcd1ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=BA=AA?= Date: Fri, 12 Jul 2024 09:43:54 +0800 Subject: [PATCH] =?UTF-8?q?connection=20isClose=20=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E5=88=A4=E6=96=AD,=E9=98=B2=E6=AD=A2=20c.ctx=20=E4=B8=8D?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E5=AF=BC=E8=87=B4=E7=A8=8B=E5=BA=8F=20panic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit connection isClose 方法判断,防止 c.ctx 不存在导致程序 panic --- znet/connection.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/znet/connection.go b/znet/connection.go index 25b04927..29521c88 100644 --- a/znet/connection.go +++ b/znet/connection.go @@ -544,9 +544,10 @@ func (c *Connection) GetMsgHandler() ziface.IMsgHandle { } func (c *Connection) isClosed() bool { - return c.ctx.Err() != nil + return c.ctx == nil || c.ctx.Err() != nil } + func (c *Connection) setStartWriterFlag() bool { return atomic.CompareAndSwapInt32(&c.startWriterFlag, 0, 1) }