Skip to content

fix(ios): reuse AVAudioEngine instance in rebuildAudioEngine to prevent owningEngine assertion crash#1014

Open
radko93 wants to merge 1 commit intosoftware-mansion:mainfrom
radko93:fix/ios-audio-engine-rebuild-owning-engine
Open

fix(ios): reuse AVAudioEngine instance in rebuildAudioEngine to prevent owningEngine assertion crash#1014
radko93 wants to merge 1 commit intosoftware-mansion:mainfrom
radko93:fix/ios-audio-engine-rebuild-owning-engine

Conversation

@radko93
Copy link
Copy Markdown

@radko93 radko93 commented Apr 10, 2026

Closes #1013

⚠️ Breaking changes ⚠️

  • None.

Introduced changes

  • reworks iOS interruption recovery in AudioEngine.mm to rebuild graph connections on the current AVAudioEngine instance instead of creating a new engine and re-attaching the same node objects
  • removes redundant reset calls before rebuildAudioEngine, since rebuild now resets the current engine internally
  • avoids reusing AVAudioSourceNode / AVAudioSinkNode instances across different AVAudioEngine instances, which can trigger AVFAudio's owningEngine assertion

Notes for reviewers

  • This change is intentionally narrow and only touches the iOS rebuild path in packages/react-native-audio-api/ios/audioapi/ios/system/AudioEngine.mm.
  • I do not have a deterministic public repro yet. The fix is based on a production crash signature plus a downstream patch that mitigated the crash in production.
  • Upstream main still had the detach-create-reattach flow when this PR was prepared on 2026-04-10.
  • Open PR Invalid engine states on recording or playback start #1005 also touches AudioEngine.mm, but it still recreates the engine in rebuildAudioEngine, so it does not address this specific owningEngine assertion. If that PR lands first, this patch will probably need a small rebase.

Checklist

  • Linked relevant issue
  • Updated relevant documentation
  • Added/Conducted relevant tests
  • Performed self-review of the code
  • Updated Web Audio API coverage
  • Added support for web
  • Updated old arch android spec file

…of creating new one

Fixes a production iOS crash (SIGABRT) where the owningEngine assertion
fires during interruption recovery. The old code detached nodes from the
current engine, created a new AVAudioEngine, and reattached the same
node objects — violating AVFAudio's ownership assumptions.

This changes rebuildAudioEngine to keep the existing engine instance and
only rebuild graph connections (disconnect/reconnect), avoiding
cross-engine node reuse. Also removes redundant reset calls before
rebuild since the method now resets internally.
@michalsek
Copy link
Copy Markdown
Member

@radko93 Hey, thanks for the PR, this is a huge help in hardening the engine! 🙌

Although we won't be able to use it as it is - reusing the engine, will cause crash/issues for other audio paths (i.e. media services were reset system notification to name one).

But i've included fixes for your issue in my pull request :)

It needs some cleanup in the test code, but should be merged within a day or two, and available in nightly version shortly after. Although I can't promise when it will be released as an stable version or patch

@radko93
Copy link
Copy Markdown
Author

radko93 commented Apr 13, 2026

@michalsek no worries, thanks for the update feel free to close this one and update the linked issues when it's fixed.

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.

iOS: interruption recovery can crash with AVAudioEngine owningEngine assertion when rebuildAudioEngine recreates the engine

2 participants