Skip to content

ladspa: stop worker thread when the plugin instance is dropped - #714

Open
aydiler wants to merge 1 commit into
Rikorose:mainfrom
aydiler:fix-ladspa-worker-thread-leak
Open

aydiler wants to merge 1 commit into
Rikorose:mainfrom
aydiler:fix-ladspa-worker-thread-leak

Conversation

@aydiler

@aydiler aydiler commented Oct 31, 2026

Copy link
Copy Markdown

Fixes #711.

Problem

get_worker_fn handles the control channel with if let Ok(..) = controls.try_recv(), so it never notices TryRecvError::Disconnected. When the host drops a DfPlugin (LADSPA cleanup), control_tx is dropped but the detached worker thread keeps polling its input queue and sleeping forever.

This matters in practice with PipeWire's filter-chain, which re-instantiates the plugin whenever the graph quantum changes, i.e. every time an app starts or stops playback. On my desktop a call-mic filter-chain running deep_filter_mono had accumulated about 710 threads after 7 days of uptime, using about 110% CPU, and the live instance logged constant Underrun detected ... Processing too slow!.

Fix

Match on try_recv() and break out of the worker loop on Disconnected. This is a behavioural no-op while the plugin is alive.

Testing

PipeWire 1.6.10, deep_filter_mono (default DeepFilterNet3_ll model) in a filter-chain at 48 kHz:

  • Before: each pw-metadata -n settings 0 clock.force-quantum <512|1024|256> left one more thread in the host process (5 → 6 → 7 → 8).
  • After: thread count stays constant across repeated quantum changes, both idle and while recording from the filtered source; the recorded audio is normal.

The worker loop ignored TryRecvError::Disconnected on the control
channel, so each dropped DfPlugin left a detached thread polling its
input queue forever. Hosts that re-instantiate the plugin often (e.g.
PipeWire filter-chain on every graph quantum change) accumulate
hundreds of busy threads over time.

Break out of the loop once the control sender is gone.

Fixes Rikorose#711
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.

LADSPA worker thread leaks permanently on plugin instance drop / cleanup

1 participant