Skip to content

fix: add mutex to VoiceActivityDetection to prevent race between generate() and unload()#1056

Open
radko93 wants to merge 1 commit intosoftware-mansion:mainfrom
radko93:fix/vad-thread-safety
Open

fix: add mutex to VoiceActivityDetection to prevent race between generate() and unload()#1056
radko93 wants to merge 1 commit intosoftware-mansion:mainfrom
radko93:fix/vad-thread-safety

Conversation

@radko93
Copy link
Copy Markdown

@radko93 radko93 commented Apr 6, 2026

Description

Add thread-safety to VoiceActivityDetection using the same mutex pattern already established by VisionModel.

Without this, BaseModel::unload() can destroy module_ on the JS thread while generate() is still calling forward() on a worker thread, causing SIGILL / SIGSEGV crashes.

Introduces a breaking change?

  • No

Type of change

  • Bug fix (change which fixes an issue)

Tested on

  • Android

Testing instructions

Use useVAD({ model: FSMN_VAD }) with continuous audio input and trigger rapid mount/unmount cycles. Confirm no crashes or deadlocks.

Related issues

Fixes #1055

…rate() and unload()

VoiceActivityDetection inherits from BaseModel but lacks the thread-safety
that VisionModel already provides. When generate() runs on a worker thread
(via ModelHostObject::promiseHostFunction) and unload() is called from the
JS thread, BaseModel::unload() destroys module_ mid-inference, causing
SIGILL/SIGSEGV crashes.

This applies the same pattern used by VisionModel:
- Add inference_mutex_ member
- Lock in generate() to protect forward() calls
- Override unload() to acquire the lock before BaseModel::unload()

Fixes software-mansion#1055
@msluszniak msluszniak added the bug fix PRs that are fixing bugs label Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug fix PRs that are fixing bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android SIGILL crash in VAD unload path

2 participants