Skip to content

Startup crash in camera portal: on_registry_global_cb reads connection->obs_pw before it is assigned #13971

Closed as not planned

Description

@TheMorpheus407

Operating System Info

Other

Other OS

NixOS 26.05, KDE Plasma 6.6 (Wayland), PipeWire 1.6.6, NVIDIA 595.71.05 (open), RTX 5090, Ryzen 9 9950X

OBS Studio Version

32.1.2

OBS Studio Version (Other)

nixpkgs build of 32.1.2. The code below is unchanged on master (a8b04ac).

OBS Studio Log URL

https://obsproject.com/logs/5zka0J7GhCMwyOUv (a start that crashed; the log ends after [pipewire] Created registry)

OBS Studio Crash Log URL

None on Linux. Backtrace from systemd-coredump below.

Expected Behavior

OBS starts normally with a "Video Capture Device (PipeWire)" source in the scene collection.

Current Behavior

OBS intermittently crashes with SIGSEGV in the PipeWire thread right after startup (2 of 10 starts on 2026-09-30, two separate cores).

PipeWire loop thread (crashed):
#0  on_registry_global_cb (linux-pipewire.so + 0x1e90a)
#1  registry_demarshal_global (libpipewire-module-protocol-native.so)
#2  process_remote (libpipewire-module-protocol-native.so)
#3  on_remote_data (libpipewire-module-protocol-native.so)
#4  loop_iterate (libspa-support.so)
#5  do_loop (libpipewire-0.3.so.0)

Main thread:
#0  __lll_lock_wait (libc.so.6)
#1  pthread_mutex_lock (libc.so.6)
#2  loop_lock (libspa-support.so)
#3  pw_thread_loop_lock (libpipewire-0.3.so.0)
#4  on_pipewire_remote_opened_cb (linux-pipewire.so)
#5  g_task_return_now (libgio-2.0.so.0)

gdb on both cores shows the same fault: mov 0x60(%rax),%rax at on_registry_global_cb+106 with rax = 0 and si_addr = 0x60. 0x60 is the offset of registry in struct _obs_pipewire, so this is obs_pipewire_get_registry(NULL).

The race:

  • on_pipewire_remote_opened_cb stores the connection only after obs_pipewire_connect_fd() returns:
    connection->obs_pw = obs_pipewire_connect_fd(pipewire_fd, &registry_events, connection);
  • obs_pipewire_connect_fd() adds the registry listener and unlocks the thread loop before it returns:
    pw_registry_add_listener(obs_pw->registry, &obs_pw->registry_listener, registry_events, user_data);
    blog(LOG_INFO, "[pipewire] Created registry %p", obs_pw->registry);
    }
    pw_thread_loop_unlock(obs_pw->thread_loop);
  • In that window the PipeWire thread can dispatch registry.global, and on_registry_global_cb reads connection->obs_pw while it is still NULL:
    registry = obs_pipewire_get_registry(connection->obs_pw);

Steps to Reproduce

  1. Use a scene collection that contains a "Video Capture Device (PipeWire)" source.
  2. Start OBS repeatedly.
  3. Some starts crash right after [camera-portal] Successfully accessed cameras / [pipewire] Created registry.

Anything else we should know?

A possible fix is to store the pointer before the loop is unlocked (for example via an out-parameter of obs_pipewire_connect_fd()), or to add the registry listener in a separate step after connection->obs_pw is assigned, under pw_thread_loop_lock. The race only exists while a PipeWire camera source is loaded.

Activity

  1. Fenrirthviti commented on Oct 1, 2026

    @Fenrirthviti
    Member

    Was this proposed fix tested?

  2. TheMorpheus407 commented on Oct 1, 2026

    @TheMorpheus407
    Author

    Not when I filed this, I only had the two cores and the code. I've tested it now.

    Setup: OBS 32.1.2 built from source with and without the patch below (only obs-studio rebuilt, same dependencies), separate config dir, one "Video Capture Device (PipeWire)" source, OBS started under gdb and quit once [camera-portal] Found device is logged. To make the race reproducible, an LD_PRELOAD shim sleeps 50 ms after every pw_thread_loop_unlock() on the main thread, which widens the window between the unlock in obs_pipewire_connect_fd() and the assignment in on_pipewire_remote_opened_cb().

    Build 50 ms shim Result
    unpatched yes 20/20 crashed in on_registry_global_cb with rax = 0 (same fault as the original cores)
    patched yes 0/20 crashed, camera found and streaming every time
    unpatched no 0/20 crashed in this harness (2 of 10 normal starts crashed on the day I filed this)
    patched no 0/10 crashed

    The patch registers the camera portal's registry listener in a new helper after connection->obs_pw has been assigned. obs_pipewire_connect_fd() itself is unchanged. With this, no caller passes registry events to it anymore, so that parameter could be dropped in a follow-up. It applies cleanly to a8b04ac.

    --- a/plugins/linux-pipewire/pipewire.h
    +++ b/plugins/linux-pipewire/pipewire.h
    @@ -44,6 +44,8 @@
     obs_pipewire *obs_pipewire_connect_fd(int pipewire_fd, const struct pw_registry_events *registry_events,
     				      void *user_data);
     struct pw_registry *obs_pipewire_get_registry(obs_pipewire *obs_pw);
    +void obs_pipewire_add_registry_listener(obs_pipewire *obs_pw, const struct pw_registry_events *registry_events,
    +					void *user_data);
     void obs_pipewire_roundtrip(obs_pipewire *obs_pw);
     void obs_pipewire_destroy(obs_pipewire *obs_pw);
     
    --- a/plugins/linux-pipewire/pipewire.c
    +++ b/plugins/linux-pipewire/pipewire.c
    @@ -1165,6 +1165,18 @@
     	return obs_pw->registry;
     }
     
    +void obs_pipewire_add_registry_listener(obs_pipewire *obs_pw, const struct pw_registry_events *registry_events,
    +					void *user_data)
    +{
    +	pw_thread_loop_lock(obs_pw->thread_loop);
    +
    +	obs_pw->registry = pw_core_get_registry(obs_pw->core, PW_VERSION_REGISTRY, 0);
    +	pw_registry_add_listener(obs_pw->registry, &obs_pw->registry_listener, registry_events, user_data);
    +	blog(LOG_INFO, "[pipewire] Created registry %p", obs_pw->registry);
    +
    +	pw_thread_loop_unlock(obs_pw->thread_loop);
    +}
    +
     void obs_pipewire_roundtrip(obs_pipewire *obs_pw)
     {
     	pw_thread_loop_lock(obs_pw->thread_loop);
    --- a/plugins/linux-pipewire/camera-portal.c
    +++ b/plugins/linux-pipewire/camera-portal.c
    @@ -1072,7 +1072,13 @@
     		return;
     	}
     
    -	connection->obs_pw = obs_pipewire_connect_fd(pipewire_fd, &registry_events, connection);
    +	connection->obs_pw = obs_pipewire_connect_fd(pipewire_fd, NULL, NULL);
    +	if (!connection->obs_pw)
    +		return;
    +
    +	/* on_registry_global_cb() reads connection->obs_pw, so only start
    +	 * receiving registry events after it has been assigned. */
    +	obs_pipewire_add_registry_listener(connection->obs_pw, &registry_events, connection);
     
     	obs_pipewire_roundtrip(connection->obs_pw);
     }

    Happy to open a PR if that's easier for you.

  3. Fenrirthviti commented on Oct 1, 2026

    @Fenrirthviti
    Member

    This is giving all the hallmarks of an AI-generated report. Was AI used to write this?

  4. TheMorpheus407 commented on Oct 1, 2026

    @TheMorpheus407
    Author

    Yes, I do let ai write together, what I found in my logs and tested, so you get it sorted properly and not my chaos writing. If that's not desired you can close the commit and tell me, Ill know for next time

  5. Fenrirthviti commented on Oct 1, 2026

    @Fenrirthviti
    Member

    Per our contribution guidelines we do not accept AI-generated content in our community.

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

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions