Skip to content

iOS: bound safe_area()'s boot-path dispatch_sync to avoid a launch deadlock - #74

Open
GenericJam wants to merge 1 commit into
masterfrom
fix/safearea-boot-timeout
Open

iOS: bound safe_area()'s boot-path dispatch_sync to avoid a launch deadlock#74
GenericJam wants to merge 1 commit into
masterfrom
fix/safearea-boot-timeout

Conversation

@GenericJam

Copy link
Copy Markdown
Owner

Summary

  • Mob.Screen.init/1 calls safe_area() synchronously before the first screen ever 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 by that point.
  • Root-caused via an Apple App Store rejection on 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.
  • Switch to 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 — clean
  • Verified via sloppy_joe (pointed mob_dir at this branch): app boots correctly on both iPhone and iPad simulators, before and after forcing UIDeviceFamily=[1] on the installed bundle (mirroring the App-Store-only device-family patch)
  • Real iPad hardware verification (pending — simulator can't accurately reproduce the iPhone-compatibility-mode window a real device uses for a UIDeviceFamily=[1] app)

🤖 Generated with Claude Code

…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>
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.

1 participant