mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 12:24:38 +03:00
Fixed a race condition in running_streams.go
This commit is contained in:
@@ -2,20 +2,27 @@ package manager
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/stashapp/stash/pkg/ffmpeg"
|
"github.com/stashapp/stash/pkg/ffmpeg"
|
||||||
"github.com/stashapp/stash/pkg/logger"
|
"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) {
|
func RegisterStream(filepath string, w *http.ResponseWriter) {
|
||||||
|
streamingFilesMutex.Lock()
|
||||||
streams := streamingFiles[filepath]
|
streams := streamingFiles[filepath]
|
||||||
|
|
||||||
streamingFiles[filepath] = append(streams, w)
|
streamingFiles[filepath] = append(streams, w)
|
||||||
|
streamingFilesMutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func deregisterStream(filepath string, w *http.ResponseWriter) {
|
func deregisterStream(filepath string, w *http.ResponseWriter) {
|
||||||
|
streamingFilesMutex.Lock()
|
||||||
|
defer streamingFilesMutex.Unlock()
|
||||||
streams := streamingFiles[filepath]
|
streams := streamingFiles[filepath]
|
||||||
|
|
||||||
for i, v := range streams {
|
for i, v := range streams {
|
||||||
@@ -37,7 +44,9 @@ func WaitAndDeregisterStream(filepath string, w *http.ResponseWriter, r *http.Re
|
|||||||
func KillRunningStreams(path string) {
|
func KillRunningStreams(path string) {
|
||||||
ffmpeg.KillRunningEncoders(path)
|
ffmpeg.KillRunningEncoders(path)
|
||||||
|
|
||||||
|
streamingFilesMutex.RLock()
|
||||||
streams := streamingFiles[path]
|
streams := streamingFiles[path]
|
||||||
|
streamingFilesMutex.RUnlock()
|
||||||
|
|
||||||
for _, w := range streams {
|
for _, w := range streams {
|
||||||
hj, ok := (*w).(http.Hijacker)
|
hj, ok := (*w).(http.Hijacker)
|
||||||
|
|||||||
Reference in New Issue
Block a user