iOS: bound safe_area()'s boot-path dispatch_sync to avoid a launch deadlock - #74
Open
GenericJam wants to merge 1 commit into
Open
iOS: bound safe_area()'s boot-path dispatch_sync to avoid a launch deadlock#74GenericJam wants to merge 1 commit into
GenericJam wants to merge 1 commit into
Conversation
…adlock Mob.Screen.init/1 calls safe_area() synchronously before the first screen mounts. A plain dispatch_sync to the main queue there is a deadlock risk if the main thread hasn't reached an idle run-loop tick yet — observed via a device-family/compatibility-mode boot hang on iPad. Switch to dispatch_async + a bounded semaphore wait, falling back to zero insets on timeout, and mark the NIF dirty (IO-bound) so a slow main thread can no longer stall a regular BEAM scheduler either. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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
Mob.Screen.init/1callssafe_area()synchronously before the first screen ever mounts. A plaindispatch_syncto the main queue there is a deadlock risk if the main thread hasn't reached an idle run-loop tick yet by that point.sloppy_joe: "the app kept loading indefinitely on launch," reproduced by the reviewer on an iPad Air 11-inch (M3) / iPadOS 26.5.2. The BEAM boot thread was blocking forever inside this NIF call, so the app never finished launching.dispatch_async+ a semaphore bounded to 2s, falling back to zero insets on timeout — a screen with wrong insets once is a far smaller bug than an app that never boots. Also mark the NIF dirty (ERL_NIF_DIRTY_JOB_IO_BOUND) so a slow main thread can no longer stall a regular BEAM scheduler either.Test plan
xcrun clang-format --dry-run -Werror ios/mob_nif.m— cleansloppy_joe(pointedmob_dirat this branch): app boots correctly on both iPhone and iPad simulators, before and after forcingUIDeviceFamily=[1]on the installed bundle (mirroring the App-Store-only device-family patch)UIDeviceFamily=[1]app)🤖 Generated with Claude Code