Skip to content

Commit

Permalink
Fix locking during session invalidation (#1377)
Browse files Browse the repository at this point in the history
* Invalidate sessions outside lock since it's an HTTP operation

* Add timeout to Mist Client calls and run session invalidation in a separate goroutine

* Add log for session invalidation
  • Loading branch information
leszko authored Sep 4, 2024
1 parent bde4fb1 commit c59ab4c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion clients/mist_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ type MistPushStats struct {
Tracks []int `json:"tracks"`
}

var mistRetryableClient = newRetryableClient(nil)
const MIST_CLIENT_TIMEOUT = 1 * time.Minute

var mistRetryableClient = newRetryableClient(&http.Client{Timeout: MIST_CLIENT_TIMEOUT})

func (mc *MistClient) AddStream(streamName, sourceUrl string) error {
c := commandAddStream(streamName, sourceUrl)
Expand Down
12 changes: 10 additions & 2 deletions handlers/accesscontrol/access-control.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,26 @@ func (ac *AccessControlHandlersCollection) periodicRefreshIntervalCache(mapic mi
time.Sleep(5 * time.Second)
ac.mutex.Lock()
refreshIntervalCache.mux.Lock()
var keysToInvalidate []string
for key := range refreshIntervalCache.data {
if time.Since(refreshIntervalCache.data[key].LastRefresh) > time.Duration(refreshIntervalCache.data[key].RefreshInterval)*time.Second {
refreshIntervalCache.data[key].LastRefresh = time.Now()
mapic.InvalidateAllSessions(key)
keysToInvalidate = append(keysToInvalidate, key)
for cachedAccessKey := range ac.cache[key] {
delete(ac.cache[key], cachedAccessKey)
}
break
}
}
ac.mutex.Unlock()
refreshIntervalCache.mux.Unlock()
ac.mutex.Unlock()

go func() {
glog.Infof("Invalidating sessions, count=%d", len(keysToInvalidate))
for _, key := range keysToInvalidate {
mapic.InvalidateAllSessions(key)
}
}()
}
}()
}
Expand Down

0 comments on commit c59ab4c

Please sign in to comment.