Skip to content

bug: linux-pipewire: quitting with a PipeWire camera source races the PipeWire thread (wrong-context warnings, occasional double free; follow-up of #393) #512

Closed

Description

@rdoupe

Follow-up of our #393, which listed this under "Not fixed here": quitting OBS with a "Video Capture Device (PipeWire)" source prints impl_ext_end_proxy called from wrong context, check thread and locking once per camera device, every time, and sometimes aborts with double free or corruption (out) or segfaults on the way out. The scene collection is saved before the crash, but the crash still triggers the AppImage's crash report and gdb relaunch, and the distribution's crash handler.

Location

  • plugins/linux-pipewire/camera-portal.c pw_portal_connection_free() (line 75), called by camera_portal_unload() when the module unloads, destroys the device table (line 82). Each entry's camera_device_free() calls pw_proxy_destroy() on the device's node proxy (line 230).
  • That runs on the thread unloading the module, without the PipeWire thread-loop lock. The PipeWire thread is still running at that point: obs_pipewire_destroy() stops it only on the next line (line 83), and it is handling the same connection (registry events, node info and params, the replies to the destroys).
  • PipeWire checks this and prints the warning for every proxy. It reports Device or resource busy when the PipeWire thread was running at that very moment, which is the race.

The code is upstream's (camera portal), unchanged in this fork apart from #393's log-line swap. Stock OBS 32.2.2 prints the same warnings on quit.

Class

Crash on quit (data race on the PipeWire connection, SIGABRT / SIGSEGV), plus a warning on every quit.

How it is reached

Quit OBS (window close, File > Exit, SIGTERM) with any PipeWire camera source in the scene collection, after the camera portal has listed the cameras.

Reproduced in the current release

AppImage 33.0.0-beta6-799-gd711a972c, headless: private Xvfb, a private D-Bus session with a fake camera portal, and a private PipeWire daemon (WirePlumber with device monitors off) with 8 producers posing as NV12 cameras. A scene collection with 8 PipeWire camera sources; OBS started, all 8 cameras negotiated, then SIGTERM.

  • Plain quits: 110 of 110 print the warning, 10 per quit, and 99 of the 110 include at least one Device or resource busy (the PipeWire thread was running during the destroy). None of those 110 crashed.
  • Quits right after reading and setting each camera's format over obs-websocket (the release check's crash case) while a test producer comes and goes: 7 of 80 crashed (5 SIGABRT with double free or corruption (out) or corrupted size vs. prev_size while consolidating, 2 SIGSEGV), each right after the warnings, during module unload. The same AppImage with the fix below: 0 of 80, and no warnings.

The release check had hit the same abort once in 15 quits with 4 cameras.

Proposed fix and failing test

Fix: destroy the device table with the PipeWire thread loop locked, through small obs_pipewire_lock()/obs_pipewire_unlock() helpers in pipewire.c.

RED test (cmocka, test_pipewire_camera_unload). It runs the real camera portal against a fake camera portal on a private D-Bus bus and a camera node on a private PipeWire daemon, like test_pipewire_camera_unplug. It is linked with --wrap to follow the camera portal's thread loop and checks every pw_proxy_destroy() made while that loop runs: it must be on the loop thread or under the loop lock. Today 3 of 3 such destroys at unload have no lock, the same in every run, in both libobs lanes.

Activity

  1. rdoupe commented on Oct 13, 2026

    @rdoupe
    CollaboratorAuthor

    Claiming: this issue.

    1. RED: test_pipewire_camera_unload runs the real camera portal against a fake portal and a private PipeWire daemon, unloads it while its PipeWire thread runs, and checks that every proxy destroyed meanwhile is destroyed on the loop thread or under the loop lock. Today 3 of 3 device proxies are destroyed without the lock.
    2. GREEN: the camera portal destroys its device table with the PipeWire thread loop locked.
      PR today.
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

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions