Fix some race conditions

This commit is contained in:
Zoe Roux 2024-02-26 22:27:47 +01:00
parent 4c7e335ef4
commit 7baa586738
3 changed files with 6 additions and 4 deletions

View File

@ -47,4 +47,4 @@ ENV NVIDIA_VISIBLE_DEVICES="all"
ENV NVIDIA_DRIVER_CAPABILITIES="all"
EXPOSE 7666
CMD wgo run .
CMD wgo run -race .

View File

@ -54,8 +54,8 @@ func (kf *Keyframe) add(values []float64) {
}
func (kf *Keyframe) AddListener(callback func(keyframes []float64)) {
kf.mutex.RLock()
defer kf.mutex.RUnlock()
kf.mutex.Lock()
defer kf.mutex.Unlock()
kf.listeners = append(kf.listeners, callback)
}
@ -72,6 +72,7 @@ func GetKeyframes(sha string, path string) *Keyframe {
save_path := fmt.Sprintf("%s/%s/keyframes.json", Settings.Metadata, sha)
if err := getSavedInfo(save_path, kf); err == nil {
log.Printf("Using keyframes cache on filesystem for %s", path)
kf.ready.Done()
return
}

View File

@ -377,6 +377,7 @@ func (ts *Stream) GetSegment(segment int32) (string, error) {
}
}
}
readyChan := ts.segments[segment].channel
ts.lock.RUnlock()
if !ready {
@ -392,7 +393,7 @@ func (ts *Stream) GetSegment(segment int32) (string, error) {
}
select {
case <-ts.segments[segment].channel:
case <-readyChan:
case <-time.After(60 * time.Second):
return "", errors.New("could not retrive the selected segment (timeout)")
}