exec pipe source that never writes hangs the whole stream forever
I run go2rtc under Frigate with a few exec sources, where ffmpeg pipes video straight into go2rtc. Every so often one of those streams would hang and never come back until I restarted go2rtc, and once it was stuck nobody else could open that stream either. I dug into it and found the cause: if the program starts but never sends any video, go2rtc waits for it forever while holding the lock for that stream, so every later viewer queues up behind it. I fixed it in my fork (vertoforce/go2rtc@527f229 and vertoforce/go2rtc@cd86fbd) and can open PRs if you want them. Details below.
Details (repro, code path, numbers; written up with AI help)Opening the source, the dial, runs under the producer's lock (producer.go:58 and
:62). A producer is go2rtc's connection to one source, so viewer two queues behind
viewer one. For a program source with no {output}, the dial waits on the first 4 bytes
of output. There is no timeout (exec.go:155). The start timeout reaches the RTSP path
only (starttimeout).
Reproduced on master c245815, config streams: {test: exec:sleep 3600}:
curl --max-time 200 "http://127.0.0.1:1984/api/stream.mp4?src=test" # client 1
curl --max-time 200 "http://127.0.0.1:1984/api/stream.mp4?src=test" # client 2Neither client gets a response. A stack dump has client 1 in that read (magic.Open)
and client 2 on the lock. Raising the timeout (#starttimeout=5) does not help, master
still hangs past 60 s. Pipe sources only: ffmpeg: sources are already bounded at 30 s.
With both fixed, the same two clients fail in 5 s and go2rtc keeps serving.
Full write-up: https://connorlake.com/findings/go2rtc-reconnect-producer-mutex-deadlock/
Source: AlexxIT/go2rtc