mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +03:00
Fixed a race condition in running_streams.go
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user