Skip to content

Take control over your live stream video by running it yourself. Streaming + chat out of the box.

Fix possible crash for concurrent map writes

Gabe Kangas3cf0035ff632
diff --git a/core/stats.go b/core/stats.go
index a793f66e07..5a2b2a0cb0 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)))
}