Repository navigation
Keep the RTMP socket and QSV fd out of children - #2310
Merged
Merged
Conversation
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
force-pushed
the
fix/more-fds-cloexec
branch
from
October 25, 2026 02:02
02aeca5 to
98de77b
Compare
rdoupe
marked this pull request as ready for review
October 25, 2026 02:02
zackees
enabled auto-merge
October 25, 2026 02:11
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Oct 25, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Oct 25, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Oct 25, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Oct 25, 2026
Member
|
Coordinator: the last three merge-queue ejections aren't caused by this PR. Since #2312, master's |
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.
4 of 7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2305
What and why
A recording starts
obs-ffmpeg-muxwithos_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).he_platform_socket()(shared/happy-eyeballs/hosts/posix/happy-eyeballs-platform.h) created it withoutSOCK_CLOEXEC, so a recording started during a stream kept a copy of the stream's TCP connection. It now usesSOCK_CLOEXEC, orfcntl(FD_CLOEXEC)where that flag does not exist (macOS). librtmp's othersocket()call, inhashswf.c, is built only withUSE_HASHSWF, which nothing defines.Initialize()opened it withoutO_CLOEXECand kept it while encoding.vaapi_open(), used by the adapter probe, did the same. Both now open withO_CLOEXEC.Initialize()(qsv11) andvaapi_open_display_drm()(obs-ffmpeg) returned without closing the node whenvaGetDisplayDRM()refused it. They now close it, andvaapi_open_display_drm()resets*fdto -1, asvaapi_close_display_drm()does.Overlap with #2285: both PRs touch
vaapi_open_display_drm(). #2285 changes theopen()line, and this PR adds two lines to the!va_dpybranch. The branches merge cleanly. With both merged, #2285'sdevice_is_opened_close_on_execstill passes: it closesfdonly whenfd >= 0, and the fd is now -1.Tests are registered in
test-graph.json.HAVE_OBS_FFMPEGandHAVE_OBS_QSV11join the graph's plugin facts intest/cmocka/CMakeLists.txt. obs-build builds neither plugin, so it sets both to false.test_happy_eyeballs_cloexecconnects to a loopback listener through the real connector and checksFD_CLOEXECon all POSIX hosts. On Linux it also starts a child withos_process_pipe_create()and reads/proc/<pid>/fd.test_qsv_open_cloexeccompiles in the realcommon_utils_linux.cpp, andtest_vaapi_open_fd_leakcompiles in the realvaapi-utils.c. Both wrapvaGetDisplayDRM()(--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 nolibvpl-dev), sotest_qsv_open_cloexecis not built there. It needs the VPL headers because the code under test callsMFXLoad()and the other VPL functions. It ran locally only (results below).test_happy_eyeballs_cloexecandtest_vaapi_open_fd_leakrun in CI.RED → GREEN
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.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.02aeca5fe(on master9d6caff9b). GREEN runs on4072f675c(rebased onff9adbf5b). The final heads, REDa78fcb2c3and GREEN98de77bfc, differ from those only by the obs-build facts squashed into RED; the test and plugin sources are identical. Local gate on98de77bfc:--test-diff origin/master,--lane lintand--lane crossall ok.--test-diff origin/masterona78fcb2c3: ok, 66/66, includingnative_test_graph_replaces_legacy_utility_definitions.Checklist
master(or the description starts with a Stacked: note)docs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): built with scripting ON (PR CI builds no OBS app: rungh workflow run ci.yml --ref <branch>for the full builds) and cross-checked with clang and MSVC