Repository navigation
Description
When an SRT stream fails to connect, OBS releases its libsrt reference twice. Examples are a server nobody listens on, a wrong passphrase, a refused streamid, or an invalid srt:// URL. libsrt counts srt_startup() calls for the whole process, and when the count reaches zero it breaks every SRT socket in the process. So each failed Start Streaming disconnects every SRT Media Source in the same OBS: FFmpeg's srt:// input uses the same libsrt. The count also goes below zero, so later on one Media Source that fails to connect stops a running SRT stream.
This is the same symptom as upstream obsproject/obs-studio#12361, "one SRT connection closing or failing tears down every other SRT connection", but it has a different trigger. #12361 is libsrt 1.5.4's own bug (Haivision/srt#3098, fixed in 1.5.5 by Haivision/srt commit dca5399b): a balanced startup/cleanup pair was enough to break other sockets. The bug here is in OBS's code and happens with every libsrt version, 1.5.2 and 1.5.7 included. The released AppImage has both bugs; the 1.5.4 half is #1082.
Location
plugins/obs-ffmpeg/obs-ffmpeg-srt.h:libsrt_open()takes a reference withsrt_startup()(line 664) and drops it withsrt_cleanup()on every failure (err:, lines 839-842).plugins/obs-ffmpeg/obs-ffmpeg-mpegts.cconnect_mpegts_url(): whenlibsrt_open()fails, it callslibsrt_close()on the same context (line 362).libsrt_close()(obs-ffmpeg-srt.hlines 884-918) callssrt_cleanup()again (line 915). It also logs a "Session Summary" and callssrt_epoll_release()/srt_close()on id 0, because the context was zero-filled and never got a socket.- libsrt 1.5.2 and 1.5.7 (
srtcore/api.cpp,CUDTUnited::cleanup()):if (--m_iInstanceCount > 0) return 0;. Otherwise they stop the GC thread, and 1.5.7 also callscloseAllSockets(), which breaks every socket ("CLEANUP: Forcefully breaking socket"). The libsrt docs say: "if you call srt_startup multiple times, you need to call the srt_cleanup function exactly the same number of times." - Upstream OBS 32.2.2 has the same code.
Reproduced
All runs were headless (private Xvfb and D-Bus, fresh profile, Simple output), loopback only, with 5 trials per row. The SRT peers were the host's ffmpeg and srt-live-transmit. A trial counts as killed when the victim's peer loses its connection, or when the victim stream leaves STARTED.
| Attack → victim | 0.1.0-beta.20261014 AppImage (libsrt 1.5.4, two copies) | master AppImage, manylinux (libsrt 1.5.2) | same, libsrt 1.5.7 |
|---|---|---|---|
(a) fresh OBS: a Media Source calls a dead srt:// port → the running SRT stream |
5/5 killed | 0/5 | 0/5 |
(b) SRT stream to a port nobody listens on → Media Source receiving srt:// (listener) |
5/5 killed | 5/5 killed | 5/5 killed |
| (b) SRT stream with a wrong passphrase → the same Media Source | 5/5 killed | 5/5 killed | 5/5 killed |
| (c) = (a) again, after the failures in (b) | 5/5 killed | 5/5 killed | 4/4 killed, then OBS died of SIGFPE while starting the 5th stream |
- Row (a) is upstream #12361. Only libsrt 1.5.4 fails it, because FFmpeg's
srt://input calls startup and cleanup in pairs. - Rows (b) and (c) are this bug. The victim Media Source's sender (ffmpeg) exits with an I/O error as soon as the stream's Start fails. On 1.5.7, OBS logs "CLEANUP: Forcefully breaking socket" for each kill (14 in that run).
- In an earlier run of the released AppImage, OBS also stopped responding while starting a stream after such failures (3 trials into row (a)).
- Stock OBS 32.2.2 (Arch, libsrt 1.5.6): row (a) 0/5. Rows (b) and (c) could not be run there. Its frontend started those streams with the out-of-process FFmpeg muxer (
obs-ffmpeg-mux), which reports STARTED without connecting, so libsrt in the OBS process is never reached.
A unit test reproduces it on every libsrt version: open and close an SRT output context the way connect_mpegts_url() does. After a rejected passphrase, a dead port, or an invalid URL, the output has made 1 srt_startup() and 2 srt_cleanup() calls. With libsrt 1.5.6, a listening socket held by another libsrt user is then broken (SRTS_BROKEN instead of SRTS_LISTENING). A small probe shows the same break from one extra srt_cleanup() on 1.5.2 and 1.5.7. 1.5.4 breaks it even after a balanced pair.
Class
Breaks other SRT connections that are working, silently, in the same OBS. Each failed or retried SRT stream start disconnects every SRT Media Source (for example remote guests or cameras over SRT). After that, a Media Source that fails once (camera off, wrong URL) stops the running SRT stream. A user who retries a stream with a typo in the passphrase sees their SRT inputs drop at each attempt. No crash is needed; the SIGFPE above is a second, rarer effect.
Proposed fix
Track the srt_startup() reference in SRTContext and drop it exactly once. libsrt_open() clears it when it cleans up after a failure, and libsrt_close() only touches a socket and calls srt_cleanup() while the context still holds the reference. Closing a failed or already closed context then does nothing, and the bogus Session Summary for a socket that never existed goes away. A failing srt_close() no longer keeps the reference either.
RED: test_srt_open_close mirrors the output's open + close against its own listener on 127.0.0.1. It counts srt_startup()/srt_cleanup() with --wrap, and checks that the listener (the "other SRT user") is still listening wherever libsrt counts references. On 1.5.4, which CI's Ubuntu 26.04 image has, it checks the count only. Three cases fail today: rejected passphrase, nobody listening, invalid URL. One guard passes: a stream that connects and stops.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
rdoupe commentedon Oct 16, 2026
Claiming: this issue.
The fix stays in
plugins/obs-ffmpeg/obs-ffmpeg-srt.h.obs-ffmpeg-mpegts.ckeeps callinglibsrt_close()after a failed open:test_srt_open_closeopens and closes an SRT output context the wayconnect_mpegts_url()does, against its own listener on 127.0.0.1. It countssrt_startup()/srt_cleanup()with--wrap. Where libsrt counts references, it also checks that the listener, which stands in for another SRT user, is still listening. Today a rejected passphrase, a dead port and an invalid URL each give 1 startup and 2 cleanups. A stream that connects and stops is the guard.srt_startup()reference in a flag.libsrt_open()andlibsrt_close()drop it exactly once, and closing a failed context does nothing.obs-ffmpeg(a failed SRT stream next to an SRT Media Source, and a failing Media Source next to a running SRT stream) on libsrt 1.5.2 and 1.5.7.test/cmocka: SRT output releases libsrt twice after a failed connect
obs-ffmpeg: Release the SRT output's libsrt reference once
obs-ffmpeg: Release the SRT output's libsrt reference once (obs-rust#…