Repository navigation
[iOS] Fix a deadlock in text measurement: run the SimpleThreadSafeCache generator outside the lock - #59614
[iOS] Fix a deadlock in text measurement: run the SimpleThreadSafeCache generator outside the lock#59614kasik96 wants to merge 1 commit into
Conversation
|
Hi @kasik96! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Summary:
Fixes #59613.
SimpleThreadSafeCacheran the generator for a cache miss while it held its mutex. For text measurement on iOS, the generator creates anNSTextStorage, and on iOS 27 devices its editing notification waits for the main queue. If the main thread measures text at the same time, it waits for the mutex, and the app hangs.Now the lock covers only the lookup and the insert, and the generator runs between them. If another thread inserted the same key meanwhile, its value is kept. Two threads can then generate the same key once each.
Changelog:
[IOS] [FIXED] - Fix a deadlock between the JS and main threads in text measurement on iOS 27
Test Plan:
GeneratorDoesNotBlockOtherThreads: the generator waits for another thread that uses the cache. It fails without this change and passes with it.ConcurrentMissKeepsFirstInsertedValue: another thread inserts the same key while the generator runs, and the cache keeps that value.