Skip to content

bug: obs-ffmpeg: SRT/RIST reconnect can crash OBS (SIGFPE) on packets left from the dropped connection #1423

Closed

Description

@rdoupe

Location

plugins/obs-ffmpeg/obs-ffmpeg-mpegts.c.h, the SRT/RIST output's restart after a dropped connection:

  • write_thread() ends on the first failed write (the caller or server went away). It signals OBS_OUTPUT_DISCONNECTED and sets stopping. The packets still queued in stream->packets, and their posts on write_sem, stay behind, along with the packets that keep arriving until libobs ends the data capture.
  • libobs reconnects through ffmpeg_mpegts_start(). That joins the old write thread, but it neither frees the leftover packets nor clears write_thread_active.
  • ffmpeg_mpegts_finalize() then starts a new write thread on a new AVFormatContext, before its header is written (the header is written by the first new packet in ffmpeg_mpegts_data()). The new thread wakes on the old posts and takes the old packets. While stopping is still set they are dropped; start() clears stopping only after finalize() returns, and a packet taken after that goes to av_interleaved_write_frame() on the context with no header. In FFmpeg, init_pts() never ran for that stream, so its priv_pts.den is 0: frac_add() divides by zero, and OBS dies with SIGFPE.
  • When the new connect fails instead (a reconnect attempt to a caller-mode server that is still down), stop() sees write_thread_active still set and ffmpeg_mpegts_deactivate() joins the old, already joined thread again. That is undefined behaviour.

Class

Crash (SIGFPE, FPE_INTDIV), intermittent; and a double pthread_join().

How it is reached

Stream over SRT, and let the connection drop and come back: for example a listener (srt://:port?mode=listener) whose receiver goes away and calls again. OBS reconnects, the receiver connects, and OBS can crash on its first write.

Reproduced in the current release

v0.1.0-beta.20261018 AppImage and master, headless (private Xvfb, private D-Bus, fresh HOME), driven over obs-websocket, with ffmpeg as the receiver. In our SRT reconnect check, which runs one listener reconnect, OBS died with SIGFPE in about 3 of 8 runs. Under gdb:

Thread "obs" received signal SIGFPE, Arithmetic exception.
#0  write_packet_common (libavformat/mux.c:89, frac_add)
#1  av_interleaved_write_frame ()
#2  mpegts_process_packet () at obs-ffmpeg-mpegts.c.h:774
#3  write_thread ()

At the crash, the packet was audio (stream_index 1) with pts 825600 at 1/48000, 17.2 s into the previous connection. total_bytes was 419 (the first packet written on the new connection), and got_headers and initialized were both false.

Fix

In ffmpeg_mpegts_start(), after joining the old write thread, clear write_thread_active and free the packets it left. The new connection then starts with an empty queue. Stacked on #1422, which changes the same start path. PR follows.

Activity

  1. rdoupe commented on Oct 18, 2026

    @rdoupe
    CollaboratorAuthor

    Claiming: fix in progress (stacked on #1422).

  2. added
    claimedAn agent or person has claimed this; check the claim comment before starting
    on Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    claimedAn agent or person has claimed this; check the claim comment before starting

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions