avoid deadlock when a runOnDemand command is used and a path is deleted

This commit is contained in:
aler9 2021-10-03 16:05:37 +02:00
parent 0a9e414625
commit 2a1b3e194d
1 changed files with 20 additions and 10 deletions

View File

@ -438,11 +438,6 @@ outer:
rp.Close()
}
if pa.onDemandCmd != nil {
pa.onDemandCmd.Close()
pa.Log(logger.Info, "runOnDemand command stopped")
}
if pa.stream != nil {
pa.stream.close()
}
@ -459,6 +454,16 @@ outer:
}
}
// close onDemandCmd after the source has been closed.
// this avoids a deadlock in which onDemandCmd is a
// RTSP publisher that sends a TEARDOWN request and waits
// for the response (like FFmpeg), but it can't since
/// the path is already waiting for the command to close.
if pa.onDemandCmd != nil {
pa.onDemandCmd.Close()
pa.Log(logger.Info, "runOnDemand command stopped")
}
pa.parent.OnPathClose(pa)
}
@ -520,16 +525,21 @@ func (pa *path) onDemandCloseSource() {
pa.source.(sourceStatic).Close()
pa.source = nil
} else {
if pa.source != nil {
pa.source.(publisher).Close()
pa.doPublisherRemove()
}
// close onDemandCmd after the source has been closed.
// this avoids a deadlock in which onDemandCmd is a
// RTSP publisher that sends a TEARDOWN request and waits
// for the response (like FFmpeg), but it can't since
/// the path is already waiting for the command to close.
if pa.onDemandCmd != nil {
pa.onDemandCmd.Close()
pa.onDemandCmd = nil
pa.Log(logger.Info, "runOnDemand command stopped")
}
if pa.source != nil {
pa.source.(publisher).Close()
pa.doPublisherRemove()
}
}
}