summaryrefslogtreecommitdiffstats
path: root/app/web_hub.go
diff options
context:
space:
mode:
authorCorey Hulen <corey@hulen.com>2017-04-04 11:42:07 -0700
committerHarrison Healey <harrisonmhealey@gmail.com>2017-04-04 14:42:07 -0400
commit6bf080393d88534aa658ecaff32ae089bd304772 (patch)
treebe25ba4cea3d687d11fe49537b84fae4bf21a484 /app/web_hub.go
parent32460bf63bc07c69ee5da0bb5640b879facb5538 (diff)
downloadchat-6bf080393d88534aa658ecaff32ae089bd304772.tar.gz
chat-6bf080393d88534aa658ecaff32ae089bd304772.tar.bz2
chat-6bf080393d88534aa658ecaff32ae089bd304772.zip
Fixing race conditions in the code base (#5966)
* Adding initial race detector * Remove setting of config twice * Fixing config file watch and config reload on license save * Fixing config file watch and config reload on license save * Fixing build error * Fixing locking issue * Fixing makefile * Fixing race in config * Fixing race in status unit test * Adding EE race tests * Fixing race in cluster info * Removing code that's isn't needed * Fixing some more races * Fixing govet issue
Diffstat (limited to 'app/web_hub.go')
-rw-r--r--app/web_hub.go9
1 files changed, 6 insertions, 3 deletions
diff --git a/app/web_hub.go b/app/web_hub.go
index a0663459a..f65683f70 100644
--- a/app/web_hub.go
+++ b/app/web_hub.go
@@ -8,6 +8,7 @@ import (
"hash/fnv"
"runtime"
"runtime/debug"
+ "sync/atomic"
l4g "github.com/alecthomas/log4go"
@@ -18,6 +19,7 @@ import (
type Hub struct {
connections []*WebConn
+ count int64
register chan *WebConn
unregister chan *WebConn
broadcast chan *model.WebSocketEvent
@@ -43,12 +45,12 @@ func NewWebHub() *Hub {
func TotalWebsocketConnections() int {
// This is racy, but it's only used for reporting information
// so it's probably OK
- count := 0
+ count := int64(0)
for _, hub := range hubs {
- count = count + len(hub.connections)
+ count = count + atomic.LoadInt64(&hub.count)
}
- return count
+ return int(count)
}
func HubStart() {
@@ -248,6 +250,7 @@ func (h *Hub) Start() {
select {
case webCon := <-h.register:
h.connections = append(h.connections, webCon)
+ atomic.StoreInt64(&h.count, int64(len(h.connections)))
case webCon := <-h.unregister:
userId := webCon.UserId