fix/DynamicFontModule - double callback invocation causing SIGABRT on Android#4030
Open
mika-bejerano wants to merge 1 commit into
Open
fix/DynamicFontModule - double callback invocation causing SIGABRT on Android#4030mika-bejerano wants to merge 1 commit into
mika-bejerano wants to merge 1 commit into
Conversation
… Android The `finally` block unconditionally called `callback.invoke(null, name)` after every execution path, including after the `catch` block already invoked the callback on error. React Native enforces single-use callbacks and throws a fatal SIGABRT when a callback is invoked more than once. Fix: move the success callback into the `try` block and remove the `finally`. The callback is now invoked exactly once — on success inside `try`, or on failure inside `catch`. Reproduces intermittently on Android (branded apps) when an exception is thrown during font loading (e.g. `Typeface.createFromFile` failing on certain devices), causing the app to crash ~4 seconds after launch before any UI interaction.
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.
Description
DynamicFontModule.loadFont(Android) had acatch/finallystructure where both blocks invoked the React Native callback, causing a fatal crash when an exception occurred during font loading.Root cause:
React Native enforces that native callbacks are invoked exactly once. When any exception is thrown during font loading (e.g.
Typeface.createFromFilefailing on certain Android devices), bothcatchandfinallyfire, invoking the callback twice and triggering a fatalSIGABRT:Fix: Move the success callback into the
tryblock and remove thefinally. The callback is now invoked exactly once — success path insidetry, error path insidecatch.Changelog
DynamicFontModule(Android) — fixed intermittent fatal crash (SIGABRT) caused by the native callback being invoked twice when an exception occurred duringloadFont. The app would crash ~4 seconds after launch before any UI interaction.Additional info
signal 6 (SIGABRT),Abort message: 'Callback arg cannot be called more than once', stack trace pointing toDynamicFontModule.loadFontTypeface.createFromFileor file I/O fails transiently)DynamicFontson startup (branded apps); standard apps are unaffectedloadFontFromFilemethod in the same file already uses the correct pattern (awasLoadedflag guarding thefinally) — this fix alignsloadFontwith that same intention, simplified