Skip to content

Fix media cache deadlocks when switching scenes - #1785

Open
aleksandr-voitenko wants to merge 2 commits into
stagingfrom
fix-memory-manager-data-races
Open

aleksandr-voitenko wants to merge 2 commits into
stagingfrom
fix-memory-manager-data-races

Conversation

@aleksandr-voitenko

Copy link
Copy Markdown
Collaborator

Description

Old memory manager has been rewritten from the ground. Fixes media-cache deadlocks that can freeze scene switching and block source cleanup.

  • Replace per-update threads with a single MediaCacheManager worker that coalesces requests, manages cache reservations, and schedules bounded readiness retries.
  • Run media queries and cache-setting updates through a bounded graphics tick callback, serializing access with source updates that can replace the media player.
  • Track sources by identity, retain references through pending work, and discard stale jobs after updates or removal.
  • Keep OBS calls and source releases outside the queue mutex. Cancel pending work and stop the manager before OBS shutdown, including when video is stopped or no sources remain.

Motivation and Context

Support issue reports scene-switch freezes with animated overlays on Windows, Streamlabs Desktop 1.21.9.

A local reproduction using the supplied WebM files exposed a circular wait between media-cache workers holding different source locks. The graphics thread subsequently blocked during source activation, freezing video processing and preventing cleanup.

This change removes those competing worker locks and makes cache scheduling and source lifetime explicit. Product changes are confined to OSN and use the existing OBS media-source caching setting.

How Has This Been Tested?

Reproduced in a stand-alone test.
Tested via controlled time advances in unit tests + Manually. Windows only.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Tweak (non-breaking change to improve existing functionality)
  • Code cleanup (non-breaking change which makes code smaller or more readable)

Old memory manager has been rewritten from the ground.
Replace per-update threads with a single worker that coalesces requests
and manages cache budgets. Run media queries and cache-setting updates
on the OBS graphics thread, and release source references outside locks.

Cancel pending work safely during removal and shutdown. Add native tests
for budgeting, readiness retries, source lifetime, and video resets.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant