Browse Source

fix race condition

pull/80/head
aler9 6 years ago
parent
commit
ca22fafdd7
  1. 2
      main.go
  2. 8
      path.go

2
main.go

@ -350,7 +350,7 @@ outer:
}() }()
for _, p := range p.paths { for _, p := range p.paths {
p.onClose() p.onClose(true)
} }
p.serverRtsp.close() p.serverRtsp.close()

8
path.go

@ -78,7 +78,7 @@ func (pa *path) onInit() {
} }
} }
func (pa *path) onClose() { func (pa *path) onClose(wait bool) {
if pa.source != nil { if pa.source != nil {
close(pa.source.terminate) close(pa.source.terminate)
<-pa.source.done <-pa.source.done
@ -104,6 +104,10 @@ func (pa *path) onClose() {
c.describe <- describeRes{nil, fmt.Errorf("publisher of path '%s' has timed out", pa.name)} c.describe <- describeRes{nil, fmt.Errorf("publisher of path '%s' has timed out", pa.name)}
} else { } else {
c.close() c.close()
if wait {
<- c.done
}
} }
} }
} }
@ -175,7 +179,7 @@ func (pa *path) onCheck() {
if !pa.permanent && if !pa.permanent &&
pa.publisher == nil && pa.publisher == nil &&
!pa.hasClients() { !pa.hasClients() {
pa.onClose() pa.onClose(false)
delete(pa.p.paths, pa.name) delete(pa.p.paths, pa.name)
} }
} }

Loading…
Cancel
Save