diff --git a/core/stats.go b/core/stats.go index a793f66e0..5a2b2a0cb 100644 --- a/core/stats.go +++ b/core/stats.go @@ -5,6 +5,7 @@ import ( "io/ioutil" "math" "os" + "sync" "time" log "github.com/sirupsen/logrus" @@ -18,6 +19,8 @@ const ( statsFilePath = "stats.json" ) +var l = sync.Mutex{} + func setupStats() error { s, err := getSavedStats() if err != nil { @@ -82,7 +85,9 @@ func SetClientActive(clientID string) { // fmt.Println("Marking client active:", clientID, s.GetViewerCount()+1, "clients connected.") // } + l.Lock() _stats.Clients[clientID] = time.Now() + l.Unlock() _stats.SessionMaxViewerCount = int(math.Max(float64(len(_stats.Clients)), float64(_stats.SessionMaxViewerCount))) _stats.OverallMaxViewerCount = int(math.Max(float64(_stats.SessionMaxViewerCount), float64(_stats.OverallMaxViewerCount))) }