Repository navigation
fix: crash-time hang reading scene window - #9282
Merged
Merged
Conversation
Size Analysis1 component analyzed iOS Builds
|
📲 Install BuildsiOS
|
Contributor
Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| c5a3e1c | 1226.65 ms | 1263.67 ms | 37.02 ms |
| ec88236 | 1219.04 ms | 1253.69 ms | 34.65 ms |
| cd4994f | 1220.89 ms | 1252.61 ms | 31.72 ms |
| 810485b | 1212.58 ms | 1252.45 ms | 39.87 ms |
| a29e132 | 1225.98 ms | 1258.31 ms | 32.34 ms |
| 5a9c804 | 1220.29 ms | 1255.17 ms | 34.88 ms |
| 3b55bda | 1224.45 ms | 1261.31 ms | 36.86 ms |
| 047965c | 1219.57 ms | 1252.02 ms | 32.45 ms |
| 22550bf | 1223.24 ms | 1259.38 ms | 36.14 ms |
| 2c9ee54 | 1226.87 ms | 1251.10 ms | 24.23 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| c5a3e1c | 24.14 KiB | 1.23 MiB | 1.20 MiB |
| ec88236 | 24.14 KiB | 1.15 MiB | 1.13 MiB |
| cd4994f | 24.14 KiB | 1.17 MiB | 1.14 MiB |
| 810485b | 24.14 KiB | 1.24 MiB | 1.22 MiB |
| a29e132 | 24.14 KiB | 1.18 MiB | 1.15 MiB |
| 5a9c804 | 24.14 KiB | 1.15 MiB | 1.13 MiB |
| 3b55bda | 24.14 KiB | 1.22 MiB | 1.20 MiB |
| 047965c | 24.14 KiB | 1.22 MiB | 1.20 MiB |
| 22550bf | 24.14 KiB | 1.23 MiB | 1.20 MiB |
| 2c9ee54 | 24.14 KiB | 1.17 MiB | 1.15 MiB |
collectWindowsOnCurrentThread() runs on the KSCrash handler thread and read the scene delegate's `window`. A Swift UIWindowSceneDelegate has a @MainActor-isolated `window` getter, so reading it off the main thread trips Swift's runtime isolation enforcement and traps with SIGTRAP inside the signal handler, hanging the process on non-Mach crashes (std::terminate, abort). Read UIWindowScene.windows on the crash thread instead, which is a plain UIKit property with no isolation check. The main-thread path (internal_getWindows) keeps reading the delegate's window, so only crash-time screenshot and view hierarchy capture change. Fixes #9281
antonis
force-pushed
the
fix/crash-screenshot-mainactor-scene-delegate
branch
from
October 5, 2026 11:31
f6d0ca7 to
ebb6514
Compare
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit ebb6514. Configure here.
antonis
marked this pull request as ready for review
October 5, 2026 12:01
antonis
requested review from
NinjaLikesCheez,
itaybre,
noahsmartin and
philprime
as code owners
October 5, 2026 12:01
itaybre
approved these changes
Oct 6, 2026
itaybre
left a comment
Contributor
There was a problem hiding this comment.
LGTM, ran and reproduced the issue with your testing case.
Proof with crash including a snapshot too: https://sentry-sdks.sentry.io/issues/7776321012/?project=5428561&query=is%3Aunresolved&referrer=issue-stream
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
During a crash, the SDK collects the app's windows so it can attach a screenshot or view hierarchy. It did this by reading the scene delegate's
windowproperty. If that delegate is written in Swift (such as Expo SDK 57'sExpoAppSceneDelegate), thewindowgetter is@MainActor-isolated, so reading it off the main thread trips Swift's isolation check and traps. Because this runs inside the crash handler, the trap re-enters the signal path and freezes the app for non-Mach crashes likestd::terminateorabort.On the crash thread the SDK now reads
UIWindowScene.windowsdirectly, a plain UIKit property with no isolation check, so the Swift getter is never called from the crash thread. The main-thread path keeps reading the scene delegate'swindowas before, so only crash-time screenshot and view hierarchy capture change.Alternative considered
The initial fix read
UIWindowScene.windowson every path, but that would have changed long-stable window selection for non-crash consumers (session replay, app-hang, view hierarchy); scoping the change to the crash thread keeps their behavior identical and limits the change to where reading the delegate is impossible anyway.💡 Motivation and Context
Fixes #9281
The regression shipped in 9.29.0 via the crash-time screenshot feature (#8986), which first called this window-collection code on the crash thread; it was previously only ever invoked on the main thread.
Impact
Latest Expo 57 (≈57.0.23+) apps that are on the UIScene lifecycle, with screenshots enabled, built for iOS 26/27.
💚 How did you test it?
📝 Checklist
You have to check all boxes before merging:
sendDefaultPIIis enabled.