Repository navigation
[iOS] App hangs on iOS 27: SimpleThreadSafeCache runs text measurement while holding its lock #59613
Description
Description
On iOS 27 devices, an app can hang for good when the JS thread and the main thread measure text at the same time.
SimpleThreadSafeCache::getMapIterator holds mutex_ while it runs the generator for a cache miss. TextLayoutManager uses this cache for text measurement, and on iOS the generator creates an NSTextStorage. On iOS 27 devices, -[NSTextStorage processEditing] posts a notification that waits for the main queue (_CFXNotificationPost → -[NSOperation waitUntilFinished]).
If the main thread measures text at that moment, for example in a synchronous commit from Reanimated, it waits for mutex_:
- JS thread: holds
mutex_and waits for the main queue. - Main thread: waits for
mutex_.
The observer that the notification waits for comes from iOS, not from app code. The iOS 27.0 simulator does not wait there, so the hang shows only on devices (seen on iOS 27.0.1 and 27.2).
The same code is on main.
Steps to reproduce
- Run on a device with iOS 27.
- Render a list of about 100 rows with text, and run a Reanimated animation.
- Replace the list data while the animation runs.
The app hangs within a few tries.
To see it on the simulator, first add a main-queue observer in lldb:
expr -l objc -- (id)[[NSNotificationCenter defaultCenter] addObserverForName:@"NSTextStorageDidProcessEditingNotification" object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *n){}]
React Native Version
0.86.3
Affected Platforms
Runtime - iOS
Output of npx @react-native-community/cli info
System:
OS: macOS 27.0.1
CPU: (10) arm64 Apple M1 Pro
Binaries:
Node: 24.14.1
Yarn: 4.3.1
npm: 11.11.0
Managers:
CocoaPods: 1.16.2
IDEs:
Xcode: 26.6/17F113
npmPackages:
react: 19.2.3
react-native: 0.86.3
react-native-reanimated: 4.5.1
iOS:
hermesEnabled: true
newArchEnabled: true
Stacktrace or Logs
Main thread:
reanimated::ReanimatedModuleProxy::commitUpdates
facebook::react::ShadowTree::commit
facebook::react::RootShadowNode::layoutIfNeeded
...
facebook::react::ParagraphShadowNode::measureContent
facebook::react::TextLayoutManager::measure
facebook::react::SimpleThreadSafeCache<...>::getMapIterator
std::mutex::lock
JS thread:
facebook::react::UIManager::completeSurface
facebook::react::ShadowTree::commit
facebook::react::RootShadowNode::layoutIfNeeded
...
facebook::react::TextLayoutManager::measure
facebook::react::SimpleThreadSafeCache<...>::getMapIterator
-[RCTTextLayoutManager measureAttributedString:paragraphAttributes:layoutContext:layoutConstraints:]
-[RCTTextLayoutManager _textStorageAndLayoutManagerWithAttributesString:paragraphAttributes:size:]
-[NSConcreteTextStorage initWithAttributedString:]
-[NSTextStorage processEditing]
-[NSNotificationCenter postNotificationName:object:userInfo:]
_CFXNotificationPost
-[NSOperation waitUntilFinished]
Reproducer
No standalone reproducer: the hang needs an iOS 27 device, or the lldb step above. The unit test in #59614 shows the lock problem without iOS.
Fix: #59614
Activity
react-native-bot commentedon Oct 29, 2026
Warning
Missing reproducer: We could not detect a reproducible example in your issue report. Reproducers are mandatory and we can accept only one of those as a valid reproducer:
You can read more about about it on our website: How to report a bug.
[-][iOS][Fabric] App hangs: SimpleThreadSafeCache runs text measurement under its mutex, and the measurement waits for the main queue[/-][+][iOS] App hangs on iOS 27: SimpleThreadSafeCache runs text measurement while holding its lock[/+]kasik96 commentedon Oct 29, 2026
A Playground or Snack can't reproduce this on its own: the hang needs iOS 27 on a device, where creating an
NSTextStoragewaits for the main queue. That wait can't be triggered from JS, and the simulator doesn't do it.Reproducers that work without a device:
GeneratorDoesNotBlockOtherThreadsin [iOS] Fix a deadlock in text measurement: run the SimpleThreadSafeCache generator outside the lock #59614 (SimpleThreadSafeCacheTest.cpp). The generator waits for another thread that uses the cache. Onmainthat thread blocks on the cache mutex and the test fails; with the fix it passes.