Skip to content

Fix spurious fd closing (os_process and v4l2) - #13198

Merged
RytoEX merged 2 commits into
obsproject:masterfrom
hoshinolina:bad-fd-closing
Mar 8, 2026
Merged

RytoEX merged 2 commits into
obsproject:masterfrom
hoshinolina:bad-fd-closing

Conversation

@hoshinolina

@hoshinolina hoshinolina commented Mar 7, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fix two bugs causing the wrong file descriptors to be closed. The os_process one is harmless but was discovered while debugging this. The v4l2loopback one is actively causing crashes.

Motivation and Context

User bug report of CEF crashes on profile switching or when closing OBS. Turns out CEF/Chromium validates fd reuse and actively asserts when something wonky happens.

How Has This Been Tested?

Tested locally, planning to push bugfix to Fedora shortly.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

The sequence should be the same for every fd:

- Close the parent end of the pipe
- If the child end of the pipe is not the intended fd already,
  - Dup it over
  - And close the old fd

This fixes a double-close() in the read path (which is fairly harmless
since it happens in the child, but sticks out in strace), some fd
leakage, and the stderr-already-is-2 case.
Comment thread plugins/linux-v4l2/v4l2-output.c Resolved
Make sure to use the invalid fd -1 when the output is not opened, and
only close valid fds. If fd 0 is closed, then this closes stdin. The
second time this happens, some other important fd will have become fd 0,
breaking something.

This causes random things to break (browser/CEF in reports, but really
it could be anything) as the wrong fds get closed.
@RytoEX RytoEX added kind/bug Categorizes issue or PR as related to a bug. platform/linux Categorizes issue or PR as affecting Linux specifically labels Mar 8, 2026
@RytoEX RytoEX self-assigned this Mar 8, 2026
@RytoEX

RytoEX commented Mar 8, 2026

Copy link
Copy Markdown
Member

I will probably merge this as-is given the approval and I myself do not understand the semantics involved, but for some historical discussion on the contents of libobs/util/pipe-posix.c, see:

@RytoEX
RytoEX merged commit 5533a27 into obsproject:master Mar 8, 2026
14 of 15 checks passed
@hoshinolina

hoshinolina commented Mar 8, 2026 via email

Copy link
Copy Markdown
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Categorizes issue or PR as related to a bug. platform/linux Categorizes issue or PR as affecting Linux specifically

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants