Avoid concurrent map read/write

This commit is contained in:
Yohann D'ANELLO 2020-11-09 18:03:15 +01:00
parent b2104a0cb7
commit d1c4f81f4e
1 changed files with 5 additions and 1 deletions

View File

@ -107,11 +107,15 @@ func statisticsHandler(w http.ResponseWriter, r *http.Request) {
uid := r.URL.Query()["uid"][0]
connectedClients[name][uid] = currentTime
}
toDelete := make([]string, 0)
for uid, oldTime := range connectedClients[name] {
if currentTime-oldTime > 40 {
delete(connectedClients, uid)
toDelete = append(toDelete, uid)
}
}
for _, uid := range toDelete {
delete(connectedClients[name], uid)
}
// Get requested stream
stream, err := streams.Get(name)