From d2c668ceea69b9a08f1a8462e0f1711b81711b10 Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Sun, 3 Oct 2021 15:58:24 +0200 Subject: [PATCH] avoid deadlock when a runOnPublish command is reading and the publisher times out (#595) (#495) --- internal/core/path.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/internal/core/path.go b/internal/core/path.go index ddaa4ea6..20e2285e 100644 --- a/internal/core/path.go +++ b/internal/core/path.go @@ -564,17 +564,22 @@ func (pa *path) sourceSetReady(tracks gortsplib.Tracks) { } func (pa *path) sourceSetNotReady() { + for r := range pa.readers { + pa.doReaderRemove(r) + r.Close() + } + + // close onPublishCmd after all readers have been closed. + // this avoids a deadlock in which onPublishCmd is a + // RTSP reader 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.onPublishCmd != nil { pa.onPublishCmd.Close() pa.onPublishCmd = nil pa.Log(logger.Info, "runOnPublish command stopped") } - for r := range pa.readers { - pa.doReaderRemove(r) - r.Close() - } - pa.sourceReady = false pa.stream.close() pa.stream = nil