From 78590139f6e9a812317d94343feae03f752ed9d1 Mon Sep 17 00:00:00 2001 From: withchao <993506633@qq.com> Date: Thu, 21 Nov 2024 17:27:14 +0800 Subject: [PATCH] fix: concurrent write to websocket connection --- internal/msggateway/client.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/msggateway/client.go b/internal/msggateway/client.go index a5e0f4cd4c..6e31751dc8 100644 --- a/internal/msggateway/client.go +++ b/internal/msggateway/client.go @@ -446,11 +446,11 @@ func (c *Client) handlerTextMessage(b []byte) error { if err != nil { return err } + c.w.Lock() + defer c.w.Unlock() if err := c.conn.SetWriteDeadline(writeWait); err != nil { return err } - c.w.Lock() - defer c.w.Unlock() return c.conn.WriteMessage(MessageText, msgData) default: return fmt.Errorf("not support message type %s", msg.Type)