Skip to content

Keep the RTMP socket and QSV fd out of children - #2310

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/more-fds-cloexec
Oct 25, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/more-fds-cloexec

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #2305

What and why

A recording starts obs-ffmpeg-mux with os_process_pipe_create(), which closes only its own pipe descriptors in the child. Every descriptor OBS holds without close-on-exec stays open in the muxer until the recording ends. Follow-up of #2278 (PR #2285).

  • RTMP stream socket: he_platform_socket() (shared/happy-eyeballs/hosts/posix/happy-eyeballs-platform.h) created it without SOCK_CLOEXEC, so a recording started during a stream kept a copy of the stream's TCP connection. It now uses SOCK_CLOEXEC, or fcntl(FD_CLOEXEC) where that flag does not exist (macOS). librtmp's other socket() call, in hashswf.c, is built only with USE_HASHSWF, which nothing defines.
  • QSV render node (Linux): Initialize() opened it without O_CLOEXEC and kept it while encoding. vaapi_open(), used by the adapter probe, did the same. Both now open with O_CLOEXEC.
  • Failure paths: Initialize() (qsv11) and vaapi_open_display_drm() (obs-ffmpeg) returned without closing the node when vaGetDisplayDRM() refused it. They now close it, and vaapi_open_display_drm() resets *fd to -1, as vaapi_close_display_drm() does.

Overlap with #2285: both PRs touch vaapi_open_display_drm(). #2285 changes the open() line, and this PR adds two lines to the !va_dpy branch. The branches merge cleanly. With both merged, #2285's device_is_opened_close_on_exec still passes: it closes fd only when fd >= 0, and the fd is now -1.

Tests are registered in test-graph.json. HAVE_OBS_FFMPEG and HAVE_OBS_QSV11 join the graph's plugin facts in test/cmocka/CMakeLists.txt. obs-build builds neither plugin, so it sets both to false.

  • test_happy_eyeballs_cloexec connects to a loopback listener through the real connector and checks FD_CLOEXEC on all POSIX hosts. On Linux it also starts a child with os_process_pipe_create() and reads /proc/<pid>/fd.
  • test_qsv_open_cloexec compiles in the real common_utils_linux.cpp, and test_vaapi_open_fd_leak compiles in the real vaapi-utils.c. Both wrap vaGetDisplayDRM() (--wrap) to refuse the display and use a temporary file as the device, so they need no GPU. The QSV wrapper also counts the copies held by a child started while the device is open.

CI coverage: PR CI's Linux Tier 2 configures with -DENABLE_QSV11=OFF (there is no libvpl-dev), so test_qsv_open_cloexec is not built there. It needs the VPL headers because the code under test calls MFXLoad() and the other VPL functions. It ran locally only (results below). test_happy_eyeballs_cloexec and test_vaapi_open_fd_leak run in CI.

RED → GREEN

  • RED commit: test: RTMP socket and QSV device leak into children. On master, all 6 cases fail on both lanes (build-c and hybrid build-rust): test_happy_eyeballs_cloexec 0/2, test_qsv_open_cloexec 0/3, test_vaapi_open_fd_leak 0/1.
  • GREEN: happy-eyeballs, qsv11: Open close-on-exec. On both lanes: test_happy_eyeballs_cloexec 2/2, test_qsv_open_cloexec 3/3, test_vaapi_open_fd_leak 1/1. The affected set (happy_eyeballs, rtmp, vaapi, qsv and cloexec tests) passes 16/16 on both lanes with no skips.
  • Commits the runs were on: RED runs on 02aeca5fe (on master 9d6caff9b). GREEN runs on 4072f675c (rebased on ff9adbf5b). The final heads, RED a78fcb2c3 and GREEN 98de77bfc, differ from those only by the obs-build facts squashed into RED; the test and plugin sources are identical. Local gate on 98de77bfc: --test-diff origin/master, --lane lint and --lane cross all ok. --test-diff origin/master on a78fcb2c3: ok, 66/66, including native_test_graph_replaces_legacy_utility_definitions.
  • Real app: not run. The change only adds close-on-exec flags and closes descriptors on failure paths, and the tests drive the real code paths.

Checklist

  • Base is master (or the description starts with a Stacked: note)
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits (N/A for docs-only; a focused CI fix may push RED and GREEN together)
  • User-visible change: its line in docs/features.md is added or updated (not applicable: no user-visible change)
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): built with scripting ON (PR CI builds no OBS app: run gh workflow run ci.yml --ref <branch> for the full builds) and cross-checked with clang and MSVC
  • Intentional differences from C listed in the parity test header and rust/README.md (ports)

OBS starts processes while it holds descriptors open: a recording
starts obs-ffmpeg-mux with os_process_pipe_create(), which closes only
its own pipe descriptors in the child. Descriptors opened without
close-on-exec stay open in the muxer for the whole recording:

- happy-eyeballs creates the RTMP stream's socket without SOCK_CLOEXEC,
  so a recording started during a stream holds the stream's TCP
  connection;
- the QSV encoder (Initialize()) and its adapter probe
  (check_adapter()) open the render node without O_CLOEXEC.

Two failure paths also leave a descriptor open: Initialize() and
vaapi_open_device() return without closing the node when
vaGetDisplayDRM() refuses it.

test_happy_eyeballs_cloexec connects to a loopback listener through the
real connector, checks FD_CLOEXEC on its socket, and on Linux starts a
child with os_process_pipe_create() and reads /proc/<pid>/fd.
test_qsv_open_cloexec compiles in the real common_utils_linux.cpp and
test_vaapi_open_fd_leak the real vaapi-utils.c, with vaGetDisplayDRM()
wrapped to refuse the display; the device is a temporary file, so they
need no GPU. The QSV wrapper also counts the copies a child started at
that moment holds. HAVE_OBS_FFMPEG and HAVE_OBS_QSV11 gate the graph
entries like the other plugin targets; obs-build, which builds neither
plugin, sets both false.

On master all 6 cases fail on both ENABLE_RUST_LIBOBS lanes.

Refs obs-rust#2305
A recording starts obs-ffmpeg-mux with os_process_pipe_create(), which
closes only its own pipe descriptors in the child, so the muxer keeps
every descriptor OBS holds without close-on-exec until the recording
ends. happy-eyeballs created the RTMP stream's socket without
SOCK_CLOEXEC: a recording started during a stream held the stream's TCP
connection. On Linux the QSV encoder opened its render node without
O_CLOEXEC and kept it while encoding; its adapter probe did the same.

Create the socket with SOCK_CLOEXEC (FD_CLOEXEC through fcntl() where
there is none, as on macOS), and open the QSV nodes with O_CLOEXEC.

Initialize() in qsv11 and vaapi_open_display_drm() in obs-ffmpeg
returned without closing the node when vaGetDisplayDRM() refused it.
Close it there; vaapi_open_display_drm() also resets *fd to -1, as
vaapi_close_display_drm() does.

librtmp's other socket() call, in hashswf.c, is built only with
USE_HASHSWF, which nothing defines.

With the fix, on both ENABLE_RUST_LIBOBS lanes (build-c, and the
hybrid build-rust): test_happy_eyeballs_cloexec passes 2 of 2,
test_qsv_open_cloexec 3 of 3 and test_vaapi_open_fd_leak 1 of 1.
Before the fix, all 6 cases failed.

Fixes obs-rust#2305
@rdoupe
rdoupe force-pushed the fix/more-fds-cloexec branch from 02aeca5 to 98de77b Compare October 25, 2026 02:02
@rdoupe
rdoupe marked this pull request as ready for review October 25, 2026 02:02
@rdoupe
rdoupe requested a review from zackees as a code owner October 25, 2026 02:02
@zackees
zackees enabled auto-merge October 25, 2026 02:11
@zackees
zackees added this pull request to the merge queue Oct 25, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 25, 2026
@zackees
zackees added this pull request to the merge queue Oct 25, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 25, 2026
@rdoupe
rdoupe added this pull request to the merge queue Oct 25, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 25, 2026
@rdoupe
rdoupe added this pull request to the merge queue Oct 25, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 25, 2026
@obs-rust-project-manager obs-rust-project-manager Bot moved this to Ready to merge in obs-rust Multiview Oct 25, 2026
@zackees

zackees commented Oct 25, 2026

Copy link
Copy Markdown
Member

Coordinator: the last three merge-queue ejections aren't caused by this PR. Since #2312, master's canonical_remux_queue_runs_unchanged pins the Qt suite at 1 test while the graph has 2. It only runs on macOS/Windows for paths like rust/obs-build, which this PR touches. #2355 fixes master; I'll re-queue this PR once it lands. Nothing for you to do.

@zackees
zackees added this pull request to the merge queue Oct 25, 2026
chriscoveries pushed a commit to chriscoveries/obsrust-fork that referenced this pull request Oct 25, 2026
…bs-rust#2355)

canonical_remux_queue_runs_unchanged pinned the Qt suite at one test.
obs-rust#2312 added test_profile_import to the suite, so the test fails on
macOS and Windows (left: 2, right: 1). Master's own lanes don't run
it there; it surfaced when obs-rust#2310, which touches rust/obs-build, was
ejected from the merge queue three times (run 40171262955).

Count the graph's Qt suite tests instead, so every one still has to
build and run and a new Qt test doesn't break the count.
Merged via the queue into obs-rust:master with commit 1d183d6 Oct 25, 2026
37 checks passed
@obs-rust-project-manager obs-rust-project-manager Bot moved this from Ready to merge to Done in obs-rust Multiview Oct 25, 2026
@rdoupe rdoupe mentioned this pull request Nov 1, 2026
4 of 7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug: linux: the RTMP socket and the QSV DRM fd leak into child processes (follow-up of #2278)

2 participants