Skip to content

Commit 3e1cbe4

Browse files
committed
fix: avoid deadlock when getting / setting position on nil source
1 parent 5b9dfd0 commit 3e1cbe4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

player/source.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ func (s *SwitchingAudioSource) SetPositionMs(pos int64) error {
7777
s.cond.L.Lock()
7878
defer s.cond.L.Unlock()
7979

80-
for s.source[s.which] == nil {
81-
s.cond.Wait()
80+
if s.source[s.which] == nil {
81+
return nil
8282
}
8383

8484
return s.source[s.which].SetPositionMs(pos)
@@ -88,8 +88,8 @@ func (s *SwitchingAudioSource) PositionMs() int64 {
8888
s.cond.L.Lock()
8989
defer s.cond.L.Unlock()
9090

91-
for s.source[s.which] == nil {
92-
s.cond.Wait()
91+
if s.source[s.which] == nil {
92+
return 0
9393
}
9494

9595
return s.source[s.which].PositionMs()

0 commit comments

Comments
 (0)