1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-05-12 06:45:46 +08:00

Merge pull request #197 from F0ur/master

fix(ws): fix concurrent write to ws conn
This commit is contained in:
Mrs4s 2020-08-26 16:27:52 +08:00 committed by GitHub
commit 0e95977ff3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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