Repository navigation
Description
Upstream OBS bug, reported by tt2468 in obsproject/obs-studio#10651 ("OBS does not de-initialize encoders on RTMP stream start fail"). Code unchanged in this fork.
Location
plugins/obs-outputs/rtmp-stream.c:1540-1546:rtmp_stream_start()initializes the output's encoders withobs_output_initialize_encoders(), returns true and connects on a separate thread.plugins/obs-outputs/rtmp-stream.c:1499-1529: when the connection fails,connect_thread()callsobs_output_signal_stop()with the error code. Data capture never began.libobs/obs-output.c:2878-2892:obs_output_end_data_capture_internal()returns early when the output is not active. Only the normal path, throughend_data_capture_thread(), stops (and so shuts down) the encoders, so after a failed start nothing shuts down the encoders that start() initialized.
Class
Resource leak: an encoder, and any hardware session it holds, stays alive after a failed output start.
How it is reached
Start a stream to a server that refuses the connection (or is unreachable) with a hardware encoder such as NVENC. The stream fails to start, but the encoder stays initialized and keeps its NVENC session until the next successful start or until OBS exits. On GPUs with a limit on concurrent NVENC sessions, the leaked session counts against it.
Reproduced headlessly on an RTX 2070 desktop with libobs, the real rtmp_output and the obs-nvenc H.264 encoder, starting the stream against a refused local port five times: after each failed start one NVENC session stays open, and it only goes away when a later stream to a listening local server starts and stops normally.
Proposed fix and failing test
Fix: on that early-return path, when the output stopped before it became active, shut down its encoders unless they are still needed: the encoder is running, or another output that uses it is active, reconnecting, delaying or still starting. Outputs get a starting flag for the last case (set before start(), cleared when data capture begins, when start() fails and on every stop path), so a second stream sharing the encoder that is still connecting keeps it. The shutdown runs on the output's existing end-capture thread, where a normal stop also shuts encoders down; the stopping thread never waits for it, and it only tries the encoder's locks, leaving the encoder initialized as before if one is busy. Failed reconnect attempts do not take this path; the encoders are shut down once reconnecting gives up. The path for an output that did start is unchanged.
RED test (cmocka, test_output_failed_start_encoders): a counting encoder, an output that fails the way rtmp_output does on a refused connection, and an output that stays "connecting" until the test lets it connect or fail. A single failed start, repeated failed starts, and two outputs sharing the encoder that both fail all leave an encoder instance behind today (3 of 6 fail). The controls pass: an encoder shared with a running output is kept, an encoder shared with an output that is still connecting is kept and that output then encodes normally, and the encoder still starts normally after a failed start. With the fix all 6 pass.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
rdoupe commentedon Oct 11, 2026
Claiming: this issue.
test_output_failed_start_encoders(3 of 6 fail today).PR within the hour.
libobs: Shut down encoders when an output stops before starting
test: Encoders must shut down after a failed output start
rdoupe commentedon Oct 11, 2026
Fixed here in obs-rust by #237, with a regression test. This was reported upstream by tt2468 in obsproject/obs-studio#10651, whose analysis (start() initializes the encoders, the connect fails, and the stop path returns early without shutting them down) is exactly where the fix went.
When an output stops before it ever started, its encoders are now shut down on the output's end-capture thread, unless another output on the same encoders is starting, active or reconnecting, so multistream setups keep their shared encoders. On an RTX 2070 desktop, five failed RTMP starts with NVENC left one NVENC session open each before the fix and none after.
Workaround on stock OBS: the leaked encoder session is released the next time a stream starts and stops normally, or when OBS restarts.
obs-rust is an AI-assisted fork of OBS; on Arch it's
obs-studio-rust-gitin the AUR.libobs: Move video encoders to the new video mix on obs_reset_video (o…