Skip to content

bug: libobs: obs_load_core_modules loads every core module again after a failed call #2730

Closed

Description

@rdoupe

Location

libobs/obs-module.c.h, obs_load_core_modules (536-551) and load_all_callback (467-477):

bool obs_load_core_modules(void)
{
	if (obs->core_modules_loaded) {
		return true;
	}
	...
	obs->core_modules_loaded = error.fail_count == 0;
	obs_module_t *existing_module = obs_get_module(info->name);
	if (info->type != OBS_MODULE_TYPE_CORE && existing_module != NULL) {
		/* "Skipping plugin ... already loaded from ..." */
		return;
	}

Also obs_open_module (129-145): after os_dlopen succeeds, the missing-exports return and the newer-libobs return leave without os_dlclose.

Class

Logic error (duplicate module load).

How it is reached

obs_load_core_modules caches only success: core_modules_loaded is true only when no failure was counted. A failure is counted when a core module was built for a newer libobs or obs_open_module returns MODULE_ERROR. A second call then walks the core module list again, and load_all_callback skips a module that is already loaded only when it is not a core module. So every core module that did load is opened again: a second obs_module goes onto obs->first_module, obs_module_set_pointer is called again, and obs_module_load runs a second time, registering the module's source, output and encoder types again.

The bundled frontend calls obs_load_core_modules once and stops on failure, so it is reached by a frontend or tool that retries the call through the public API. No upstream issue.

The missing os_dlclose in obs_open_module matches free_module, which has not closed module libraries since upstream obs-studio commit 2446f62 ("Do not call dlclose on modules", 2014): unloading a library whose constructors registered something can crash later. That one is deliberate and only gets a comment saying so.

Proposed fix and failing test

  • In load_all_callback, skip a core module that is already loaded (with a debug log), as plugins are. Leave the success-only cache as it is, so a retry still reports the failure.
  • In obs_open_module, comment that the two early returns leave the library loaded on purpose, as free_module does.

Test (RED first): a new case in test/cmocka/test_core_module_load.c. The child lays out the stub core modules with the first one built for a newer libobs, calls obs_load_core_modules twice and reports how many entries each core module has in the loaded module list. Both calls return false; today every other core module has two entries after the second call, and after the fix exactly one.

Activity

  1. added
    bug
    on Oct 28, 2026
  2. zackees commented on Oct 28, 2026

    @zackees
    Member

    Claiming: libobs: stop obs_load_core_modules reloading already-loaded core modules (#2730)

    Plan (one PR, fix/2730-core-module-reload):

    1. RED: new case in test/cmocka/test_core_module_load.c — the child calls obs_load_core_modules() twice against stub core modules where the first is built for a newer libobs, and reports how many entries each core module has in the loaded list. Both calls return false; today the other core modules have two entries after the second call.
    2. GREEN: in load_all_callback, skip a core module that is already in obs_get_module(), with a debug log, as plugins are skipped. Keep the success-only cache so a retry still reports the failure.
    3. Comment in obs_open_module that the two early returns leave the library loaded on purpose (matching free_module, upstream 2446f62); no os_dlclose.
    4. Run test_core_module_load in the Tier 2 build volume, open the PR with the RED/GREEN evidence, Fixes #2730.
  3. added
    ready
    on Oct 28, 2026
  4. added a commit that references this issue on Oct 28, 2026
    df6b3ab
  5. zackees commented on Oct 28, 2026

    @zackees
    Member

    Fixed in #2732 (merged as 01279b76b queue entry; squash-merged).

    What landed: load_all_callback now skips a core module that is already in the module list (with the same debug log the plugin branch uses), so a second obs_load_core_modules after a failed call no longer registers every already-loaded core module's source/output/encoder types again; the success-only core_modules_loaded cache is unchanged, so a retry still reports the failure. obs_open_module's two early returns keep the library loaded on purpose, with a comment saying so (same policy as free_module since upstream 2446f62).

    Evidence: the new test/cmocka/test_core_module_load.c case (a_failed_load_does_not_reload_the_core_modules_that_did_load) RED on d502777eb and GREEN on df6b3abfb; the Linux Tier 2 lane, Flatpak-adjacent lanes, Format and CI Gate ✅ all passed on the branch.

    Nothing is left on this issue; the obs_dlclose observation was documentation-only by design.

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

Metadata

Metadata

Assignees

Labels

bugready

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions