Skip to content

fix deadlock on fast init deinit of filters#718

Merged
summeroff merged 2 commits intostreamlabsfrom
fix_filter_deadlock
Apr 2, 2026
Merged

fix deadlock on fast init deinit of filters#718
summeroff merged 2 commits intostreamlabsfrom
fix_filter_deadlock

Conversation

@summeroff
Copy link
Copy Markdown

@summeroff summeroff commented Apr 2, 2026

Summary

  • Fix deadlock in nvidia_audio_destroy when NVIDIA audio filters are rapidly created and destroyed (e.g. during automated tests that iterate through all filter types)

Problem

nvidia_audio_destroy locks ng->nvafx_mutex and then calls pthread_join on the init thread. The init thread (nvidia_audio_initialize) also needs to acquire ng->nvafx_mutex as its first step. When deferred destruction
runs before the init thread has acquired the mutex, this creates a deadlock:

  • Destroy thread: holds nvafx_mutex, waits on pthread_join
  • Init thread: waits on nvafx_mutex, never finishes

This cascades to nvidia_afx_initializer_mutex (the global mutex shared across all NVIDIA audio filter instances), blocking initialization of any subsequent NVIDIA audio filters and stalling obs_wait_for_destroy_queue.

Fix

Move pthread_join before the mutex lock in nvidia_audio_destroy. The init thread runs to completion first (releasing all locks), then destroy safely locks the mutex for cleanup.

Types of changes

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

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the streamlabs branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

@summeroff summeroff merged commit c8e9cc2 into streamlabs Apr 2, 2026
14 checks passed
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.

3 participants