Handle null AudioUnit gracefully after failed reinit#276
Open
kinetiknz wants to merge 1 commit intotrailblazerfrom
Open
Handle null AudioUnit gracefully after failed reinit#276kinetiknz wants to merge 1 commit intotrailblazerfrom
kinetiknz wants to merge 1 commit intotrailblazerfrom
Conversation
After a failed device reinit, AudioUnits are closed (nulled) and the stream enters an error state, but calls to set_volume or set_input_processing_params can still arrive before the client processes the error notification. These calls are dispatched to the serial queue, where they encounter a null AudioUnit and crash the process (~95 crash pings per 30 days on macOS). Fix: - Convert assert!(!unit.is_null()) to error returns with logging in set_volume, get_volume, set_input_mute, and set_input_processing_params. Retain debug_assert so unexpected null units are still caught in dev builds. - Set stopped=true in the reinit_async error path so the stream is in a consistent non-operational state after failed reinit, preventing callbacks from running on a closed stream.
ChunMinChang
approved these changes
Mar 26, 2026
| fn set_volume(unit: AudioUnit, volume: f32) -> Result<()> { | ||
| assert!(!unit.is_null()); | ||
| debug_assert!(!unit.is_null()); | ||
| if unit.is_null() { |
Member
There was a problem hiding this comment.
It's not easy to tell why both assertion and if-check for non-null both exist here without checking the commit message or PR, mind adding some comment somewhere?
This situation makes me wonder what else APIs we shouldn't call after the stream runs into the error state. We don't have a state variable indicating the stream status now, but maybe we should? That would be in another PR I think.
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.
After a failed device reinit, AudioUnits are closed (nulled) and the stream enters an error state, but calls to set_volume or set_input_processing_params can still arrive before the client processes the error notification. These calls are dispatched to the serial queue, where they encounter a null AudioUnit and crash the process (~95 crash pings per 30 days on macOS).
Fix: