fix: concurrent write to websocket connection

This commit is contained in:
withchao 2024-11-21 17:27:14 +08:00
parent af2f0209d6
commit 78590139f6

View File

@ -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)