Skip to content

linux-pipewire: Fail cleanly when the PipeWire client cannot start - #429

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/pipewire-context-null
Oct 13, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/pipewire-context-null

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Description

A scene with a PipeWire screen capture crashed OBS while it loaded whenever the PipeWire client couldn't start. The continuous AppImage hit this on every launch: it points PIPEWIRE_CONFIG_DIR at a directory it doesn't package. With this, the capture stays empty and the log says why. OBS keeps running.

  1. test: Crash when PipeWire has no client configuration (RED) adds test_pipewire_context_fail. The failure cases need no PipeWire daemon (the configuration is read before connecting, and a socketpair stands in for the portal's fd), so they also run in CI images without PipeWire installed. Only the control case needs a daemon: test_pipewire_context_fail.sh starts a private one when pipewire is installed, with its own runtime dir and a minimal configuration (native protocol and access control only: no D-Bus, no realtime or X11 modules, no session manager, no devices), and that case skips otherwise. missing_configuration_fails_cleanly segfaults on this commit.
  2. linux-pipewire: Fail cleanly when the PipeWire client cannot start:
    • obs_pipewire_connect_fd() now checks pw_thread_loop_new() and pw_context_new(). Before, it passed a NULL context to pw_context_connect_fd(), which dereferenced it.
    • The log names the likely cause: [pipewire] Error creating PipeWire context: <errno> (is the PipeWire client configuration missing?).
    • Every failure path stops and frees what it set up and closes the portal's fd. Callers don't close it, so the old core-failure path leaked the fd, the context and a running thread loop. Not covered here: the duplicate fd handed to pw_context_connect_fd() can still leak if PipeWire fails before taking it over; that predates this change and is left for a follow-up.
    • During a reconnect, the screencast source counts a failed connection as a failed attempt and retries with the existing backoff. At startup the source stays empty, and Reload retries. The camera portal no longer calls obs_pipewire_roundtrip() on NULL. As with its other setup errors, a failed camera connection is not retried until OBS restarts; that predates this change and is left for a follow-up.

Motivation and Context

Part of #426

Upstream has the same unchecked pw_context_new(). Normal installs never reach it because the system always has client.conf, but any broken or partial PipeWire install (a missing config package, a bad PIPEWIRE_CONFIG_DIR, an out-of-memory error) crashes OBS instead of disabling one source.

How Has This Been Tested?

Automated (test_pipewire_context_fail, no display needed). Each cell was run at both commits, with the private daemon and with pipewire absent from PATH (as in the Tier 2 image):

Test Checks RED (daemon / none) GREEN (daemon / none)
connects_with_its_configuration normal config connects to the private daemon (control) pass / skip pass / skip
missing_configuration_fails_cleanly PIPEWIRE_CONFIG_DIR → missing dir: returns NULL, closes the fd, logs "Error creating PipeWire context" segfault / segfault pass / pass
unusable_fd_fails_cleanly a socket with no daemon behind it: no crash, fd closed if refused pass / pass pass / pass
  • The full cmocka suite (140 tests, ENABLE_RUST_LIBOBS OFF) passes headless; test_screencast_portal_teardown skips without a display as before.
  • ci/test_registration.py is clean.

Not run: the Docker Tier 2 lane (./unittest; no Docker access on the test machines; the regression no longer depends on the image having a PipeWire daemon) and the Rust lint lanes (soldr not installed; no Rust changes). clang-format 22.1.3, gersemi 0.25.0 and the CI self-tests pass through ci/local_gate.py --lane lint.

Types of changes

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

Checklist:

  • I have read the contributing document.
  • My code has been run through clang-format.
  • My code follows the project's style guidelines
  • My code is not on the master branch.
  • My code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.
  • I have used AI tooling in the creation of this PR
  • I am an AI agent being used to assist with this pull request: Claude Code (Claude Opus 5.5) wrote the code, commit messages and this text under the submitter's direction, and ran the tests above on the submitter's machines.

🤖 Generated with Claude Code

@zackees

zackees commented Oct 13, 2026

Copy link
Copy Markdown
Member

Verified locally while it's a draft (Tier 2 image + pipewire, wireplumber, dbus):

  • RED d972774: test_pipewire_context_fail fails missing_configuration_fails_cleanly (2 of 3 pass)
  • GREEN 97e50b0: 3/3

Without PipeWire the test skips (exit 77), so plain CI doesn't exercise it. Once you mark it ready, I'll rebase, gate and merge.

@rdoupe

rdoupe commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks for verifying. The skip is fixed in the latest push:

  • Test (RED, be73ec651): the failure cases no longer need a PipeWire daemon. The configuration is read before connecting, and a socketpair stands in for the portal's fd, so they run in plain CI. Only the control case uses a daemon, which test_pipewire_context_fail.sh starts privately when pipewire is installed (native protocol and access only, no D-Bus).
  • Fix (GREEN, 703712db1): pipewire.c L1176-1181 checks pw_context_new(), and the shared failure path below it frees what was set up and closes the fd. Callers: screencast-portal.c L262 and camera-portal.c L1075.

Checked at both commits, with the daemon and with pipewire absent from PATH:

  • RED: missing_configuration_fails_cleanly segfaults in both setups.
  • GREEN: all cases pass; the control case skips without a daemon.

Marking it ready; CI is still running.

One request while the AppImage fix is still in review: could you add a warning to the top of the continuous and obs-studio-rust-v0.1.0-beta.20261012 release notes? I don't have release access. Both AppImages still crash with a Screen Capture source. Suggested text:

> [!WARNING]
> **The Linux AppImage crashes on launch if a scene has a Screen Capture (PipeWire) source** (the usual capture on Wayland). A fix is in progress: #426. Until then, use another build or remove the Screen Capture source before launching.

continuous rewrites its notes on every master push, so it would need re-adding (or a line in appimage.yaml's notes) until the packaging fix lands.

@rdoupe
rdoupe marked this pull request as ready for review October 13, 2026 02:48
@rdoupe
rdoupe requested a review from zackees as a code owner October 13, 2026 02:48
rdoupe and others added 2 commits October 12, 2026 19:54
A PipeWire client without its configuration crashed OBS at launch: the
obs-rust AppImage pointed PIPEWIRE_CONFIG_DIR at a directory that was not
packaged, so pw_context_new() returned NULL and obs_pipewire_connect_fd()
passed that on to pw_context_connect_fd(). Any scene with a PipeWire
screen capture crashed while loading.

Against a private PipeWire daemon, connecting with a missing configuration
directory must return NULL, log why and close the fd it was given.
missing_configuration_fails_cleanly segfaults here.

Part of obs-rust#426

Co-Authored-By: Claude Opus 5.5 <[email protected]>
obs_pipewire_connect_fd() did not check pw_thread_loop_new() or
pw_context_new(). When PipeWire cannot load its client configuration
(client.conf), pw_context_new() returns NULL and pw_context_connect_fd()
then dereferenced it, so a scene with a PipeWire screen capture crashed
OBS while loading. The obs-rust AppImage hit this: it pointed
PIPEWIRE_CONFIG_DIR at a directory that was not packaged.

Check every step, log the cause, and on failure stop and free what was
set up and close the portal's fd, which the callers do not close. The
screencast source counts a failed connection as a failed reconnect
attempt, and the camera portal no longer runs a roundtrip on NULL.

Part of obs-rust#426

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=62ed7f49bb37a9530761cdcbab1a76599b436da8 secs=151 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791860250,"gate":"rust/all/fmt","host":"linux-x86_64","key":"a3b91dc812031b9a85d60ac666b5931775fd2f24ac926f40cbd676812975ff73","lane":"lint","parents":["de5bedf065eb11cabd706f5fcb8dc69b27531e98"],"secs":27,"stamp":"1f9ed8a33f594ed4cc0096267d35a065","tree":"62ed7f49bb37a9530761cdcbab1a76599b436da8","v":1,"via":"run"}
Ci-Attestation: {"at":1791860250,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"a3b91dc812031b9a85d60ac666b5931775fd2f24ac926f40cbd676812975ff73","lane":"lint","parents":["de5bedf065eb11cabd706f5fcb8dc69b27531e98"],"secs":27,"stamp":"d37e08b4902f8b62cb8ecdf4aafc44b0","tree":"62ed7f49bb37a9530761cdcbab1a76599b436da8","v":1,"via":"run"}
Ci-Attestation: {"at":1791860250,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"c773801b99a98194eb42360c4158f9a07be0f92ad5e3430ec8a8709431d3cd7c","lane":"rust-test","parents":["de5bedf065eb11cabd706f5fcb8dc69b27531e98"],"secs":53,"stamp":"bd53e1fd5a4e4c54be179349dc69b0f2","tree":"62ed7f49bb37a9530761cdcbab1a76599b436da8","v":1,"via":"run"}
Ci-Attestation: {"at":1791860250,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"a5006369b8ff6fcb2cdcdc96f0bbe37cf2b125f0e8d15fe7d00effd83419b7f8","lane":"tier2-linux","parents":["de5bedf065eb11cabd706f5fcb8dc69b27531e98"],"secs":71,"stamp":"0bf8b85b73e747b661b7683b7675033d","tree":"62ed7f49bb37a9530761cdcbab1a76599b436da8","v":1,"via":"run"}
@zackees

zackees commented Oct 13, 2026

Copy link
Copy Markdown
Member

Re-verified on the ready head (Tier 2 image + pipewire, wireplumber, dbus):

  • RED be73ec6: missing_configuration_fails_cleanly fails (2 of 3 pass)
  • GREEN 703712d: 3/3
  • Rebased on master, local gate passed; pushed as d51aa53.

@zackees
zackees force-pushed the fix/pipewire-context-null branch from 703712d to d51aa53 Compare October 13, 2026 02:57
@zackees
zackees merged commit 7ddbbb5 into obs-rust:master Oct 13, 2026
23 checks passed
rdoupe added a commit to rdoupe/obs-studio that referenced this pull request Oct 13, 2026
Every published AppImage crashed on start for anyone whose scene holds a
PipeWire screen capture: the bundled libpipewire was pointed at module and
config directories that were never bundled, pw_context_new() returned NULL
and the next PipeWire call segfaulted (obs-rust#429 now turns that into a dead
source). The AppImage test passed anyway: it only started OBS once with an
empty profile, where nothing touches PipeWire, so the broken build was
published.

test-appimage.sh now takes one scenario, and CI runs each in its own fresh
stock container, so nothing one scenario starts or leaves behind can affect
another:

1. bundle: check-appdir.sh requires every path AppRun exports into the
   AppDir to exist, PipeWire's client.conf with the modules and SPA plugins
   it loads, gconv and Qt's X11 and Wayland plugins; every bundled ELF
   file must resolve its libraries and symbols from the bundle with the
   bundled loader, and every module the build installed must be there. No
   desktop-session package is installed in this scenario.
2. first-start: a new profile opens a window that renders, then OBS must
   quit on SIGINT, by itself, with status 0.
3. probes: a test helper (testkit.c, built next to the AppImage and run
   next to obs with the same RPATH and AppRun's environment) connects to
   PipeWire and PulseAudio, converts text through gconv and uses the
   session bus.
4. saved-profile: OBS starts with a returning user's scene (PipeWire
   screen capture, PipeWire camera, PulseAudio microphone) and
   --startrecording, against a private D-Bus, PipeWire, WirePlumber and
   pipewire-pulse, a fake ScreenCast/Camera portal served by the helper,
   and test producers (colour bars, a bouncing ball, a 440 Hz tone). OBS
   must get its PipeWire connection from the portal, stay up, map
   PipeWire, PulseAudio and GLib from the AppImage, load every module the
   build installed, start every source and quit cleanly.
   verify-recording.sh then checks, outside the container, that the
   recording decodes at 320x240 with enough frames, both pictures keep
   moving and the tone is there throughout; its --self-test proves it
   fails on a frozen picture, a silent microphone and a broken file.
   Only Ubuntu 22.04, whose PipeWire 0.3.x cannot run the producers, runs
   it without them; an unreadable or old PipeWire anywhere else fails.

Every scenario ends by stopping what it started and fails if any of it,
or any OBS, is still running 10 s later or an OBS instance socket is still
open. AppRun hides a crash from its caller (it saves a report and starts
OBS again under gdb), so any AppRun crash report fails the scenario too.
The test only signals processes it started, picks a free X display and
clears the caller's session variables first.

The daily beta (release-rust.yaml) took the AppImage artifact even when
its tests had failed; it now takes it only when the appimage workflow
passed. The continuous release already waits for every test job.

Refs obs-rust#426

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

2 participants