fix: guard qwen_engine std::Mutex poison + null ctx FFI calls#630
Merged
H-Chris233 merged 1 commit intoJun 9, 2026
Merged
Conversation
Two crash-risk fences on the dictation hot path: 1. set_token_handler: Replace std::sync::Mutex::lock().expect() with unwrap_or_else(|poisoned| poisoned.into_inner()) to survive a poisoned mutex instead of panicking the process. This is the ONLY std Mutex in the codebase (all others use parking_lot). If token_trampoline's C FFI callback panics, the Mutex poisons and the next dictation crashes. 2. transcribe_audio / transcribe_stream: Add is_null() guard before C FFI calls to prevent UB if engine is somehow used after Drop (defense- in-depth under normal Arc ownership).
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
修复 dictation 热路径上的潜在崩溃
审计发现 `src/asr/local/qwen_engine.rs` 是整个 codebase 中唯一使用 `std::sync::Mutex`(会 poison)而非 `parking_lot::Mutex` 的锁,位于本地 ASR dictation 热路径上。
修复点
`set_token_handler` — Mutex poison 防护
`transcribe_audio` / `transcribe_stream` — null ctx 防护
验证
PR Type
Bug fix
Description
Recover from poisoned Mutex in token handler setter
Guard null ctx before C FFI calls in transcribers
Diagram Walkthrough
flowchart LR A["set_token_handler lock"] --> B["Recover from poison (unwrap_or_else)"] C["transcribe_audio/stream"] --> D["Return error if ctx is null"]File Walkthrough
qwen_engine.rs
Guard Mutex poison and null ctxopenless-all/app/src-tauri/src/asr/local/qwen_engine.rs
lock().expect()withunwrap_or_elsefor poisoned Mutexrecovery
is_null()check before FFI calls to avoid undefined behavior