Fixed a race condition in running_streams.go

This commit is contained in:
Stash Dev
2019-11-07 11:12:40 -08:00
committed by StashAppDev
parent 84bee2eb60
commit 7416a8237d

View File

@@ -2,20 +2,27 @@ package manager
import (
"net/http"
"sync"
"github.com/stashapp/stash/pkg/ffmpeg"
"github.com/stashapp/stash/pkg/logger"
)
var streamingFiles = make(map[string][]*http.ResponseWriter)
var (
streamingFiles = make(map[string][]*http.ResponseWriter)
streamingFilesMutex = sync.RWMutex{}
)
func RegisterStream(filepath string, w *http.ResponseWriter) {
streamingFilesMutex.Lock()
streams := streamingFiles[filepath]
streamingFiles[filepath] = append(streams, w)
streamingFilesMutex.Unlock()
}
func deregisterStream(filepath string, w *http.ResponseWriter) {
streamingFilesMutex.Lock()
defer streamingFilesMutex.Unlock()
streams := streamingFiles[filepath]
for i, v := range streams {
@@ -37,7 +44,9 @@ func WaitAndDeregisterStream(filepath string, w *http.ResponseWriter, r *http.Re
func KillRunningStreams(path string) {
ffmpeg.KillRunningEncoders(path)
streamingFilesMutex.RLock()
streams := streamingFiles[path]
streamingFilesMutex.RUnlock()
for _, w := range streams {
hj, ok := (*w).(http.Hijacker)