mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-05 03:23:49 +08:00
fix(ws): fix concurrent write to ws conn
This commit is contained in:
parent
174bb0bbe1
commit
fe7a1f5028
@ -319,6 +319,7 @@ func (s *websocketServer) onBotPushEvent(m coolq.MSG) {
|
||||
for i, l := 0, len(s.eventConn); i < l; i++ {
|
||||
conn := s.eventConn[i]
|
||||
log.Debugf("向WS客户端 %v 推送Event: %v", conn.RemoteAddr().String(), m.ToJson())
|
||||
conn.Lock()
|
||||
if err := conn.WriteMessage(websocket.TextMessage, []byte(m.ToJson())); err != nil {
|
||||
_ = conn.Close()
|
||||
next := i + 1
|
||||
@ -330,7 +331,9 @@ func (s *websocketServer) onBotPushEvent(m coolq.MSG) {
|
||||
i--
|
||||
l--
|
||||
conn = nil
|
||||
continue
|
||||
}
|
||||
conn.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user