fix: prevent abort on quit by handling poisoned mutexes in Drop impls#1354
Open
marcel-dias wants to merge 1 commit into
Open
fix: prevent abort on quit by handling poisoned mutexes in Drop impls#1354marcel-dias wants to merge 1 commit into
marcel-dias wants to merge 1 commit into
Conversation
During app termination, macOS sends a quit event which triggers `exit()` → `__cxa_finalize_ranges` → Rust Drop handlers. If a mutex was poisoned by a prior panic anywhere in the transcription pipeline, calling `.lock().unwrap()` inside a Drop impl triggers a second panic. Rust treats panic-during-Drop as unrecoverable and calls `abort()`, crashing the app instead of exiting cleanly. Replace `.lock().unwrap()` with `match` + `into_inner()` in both `TranscriptionManager::drop()` and `LoadingGuard::drop()` so they gracefully recover poisoned mutexes during cleanup. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Owner
|
Thanks we will pick this up after review |
Author
|
I believe I was able to map the steps that cause the issue. I'm using I changed the |
Owner
|
Interesting @marcel-dias thanks for the info |
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.
Summary
.lock().unwrap()withmatch+into_inner()inTranscriptionManager::drop()andLoadingGuard::drop()to preventabort()on app quitProblem
When macOS sends a quit event (Cmd+Q, system shutdown, etc.), the app terminates via
[NSApplication terminate:]→exit()→__cxa_finalize_ranges, which runs Rust Drop handlers. If a mutex was poisoned by a prior panic anywhere in the transcription pipeline, calling.lock().unwrap()inside a Drop impl triggers a second panic. Rust treats panic-during-Drop as unrecoverable and callsabort(), producing aSIGABRTcrash instead of a clean exit.The two affected locations:
TranscriptionManager::drop()(transcription.rs:846) —.lock().unwrap()onwatcher_handleLoadingGuard::drop()(transcription.rs:59) —.lock().unwrap()onis_loadingNote:
HandyKeysState::drop()already usesif let Ok(...)which correctly handles poisoned locks.Fix
Use
PoisonError::into_inner()to recover the underlyingMutexGuardeven when the mutex is poisoned. This is the standard Rust pattern for "I need this data during cleanup regardless of prior panics."Test plan
cargo check/cargo clippypass🤖 Generated with Claude Code