问答 / 82 / 5 / 创建于 1周前 / 更新于 1周前
使用 gorilla/websocket 库,在发送消息的前面已判断 Conn == nil 值时进行 continue,为什么还会继续往下走.
经排查后发现不是由于 websocket.conn == nil 引起的问题,而是因在执行 websocket.Write 前的一段获取是否有发送的数据导致的。获取数据的这块逻辑没有加锁。 示例代码:
websocket.conn == nil
func (sc *SocketConn) Getmsg() []byte { by := []byte{} if len(sc.QueueBy) > 0 { by = sc.QueueBy[0] sc.QueueBy = sc.QueueBy[1:] } return by }
为什么不return
我要举报该,理由是:
推荐文章: