все предусмотреть. Подскажите где тут именно может быть гонка?
func (sub *Subscription) GetListPeers(count int64) *ListPeers {
→ var listPeers = make(ListPeers, 0, count)
→ var countPeers int64 = 0
→ hub.RLock()
→ defer hub.RUnlock()
→ priorities := sub.GetClientPriority()
→ info := sub.Peer.Info
→ mapPeers := make(map[uuid.UUID]bool)
→ for _, priority := range priorities {
→ → key := info.getKey(priority)
→ → if key == nil {
→ → → continue
→ → }
→ → for clientID, peer := range hub.Peers[sub.ClientName][sub.StreamName][key] {
→ → → if count <= countPeers {
→ → → → return &listPeers
→ → → }
→ → → if clientID == sub.Peer.PeerID {
→ → → → continue
→ → → }
→ → → if !mapPeers[peer.PeerID] && sub.isSuitablePeer(peer) {
→ → → → mapPeers[peer.PeerID] = true
→ → → → //TODO from slice to map
→ → → → listPeers = append(listPeers, peer.PeerID)
→ → → → countPeers++
→ → → }
→ → }
→ }
→ logging.Printf("INFO", "Get peers %s, %s, %s, %s, %v\n", sub.Peer.Info.IPAddress, sub.ClientName, sub.StreamName, s
→ return &listPeers
}
с флагом -race грешит именно на эту функцию
к этой функции обращается большое количество горутюн
WARNING: DATA RACE
Write at 0x00c0000504e0 by goroutine 421:
core.(*Subscription).GetListPeers()
core/client.go:133 +0x246
core.(*Subscription).readPump()
core/client.go:232 +0x1034
Previous write at 0x00c0000504e0 by goroutine 225:
core.(*Subscription).GetListPeers()
core/client.go:133 +0x246
core.(*Subscription).readPump()
core/client.go:232 +0x1034
Goroutine 421 (running) created at:
core.ServeRequest()
core/client.go:380 +0xc73
main.webSocket()
main.go:24 +0x4c
net/http.HandlerFunc.ServeHTTP()
/usr/local/go/src/net/http/server.go:1995 +0x51
net/http.(*ServeMux).ServeHTTP()
/usr/local/go/src/net/http/server.go:2375 +0x28a
net/http.serverHandler.ServeHTTP()
/usr/local/go/src/net/http/server.go:2774 +0xce
net/http.(*conn).serve()
/usr/local/go/src/net/http/server.go:1878 +0x811
Goroutine 225 (running) created at:
core.ServeRequest()
core/client.go:380 +0xc73
main.webSocket()
main.go:24 +0x4c
net/http.HandlerFunc.ServeHTTP()
/usr/local/go/src/net/http/server.go:1995 +0x51
net/http.(*ServeMux).ServeHTTP()
/usr/local/go/src/net/http/server.go:2375 +0x28a
net/http.serverHandler.ServeHTTP()
/usr/local/go/src/net/http/server.go:2774 +0xce
net/http.(*conn).serve()
https://goplay.space
что за тип ListPeers?
А что за hub?
Обсуждают сегодня