Skip to content

[iOS] Fix a deadlock in text measurement: run the SimpleThreadSafeCache generator outside the lock - #59614

Closed
kasik96 wants to merge 1 commit into
react:mainfrom
kasik96:fix-simple-thread-safe-cache-deadlock
Closed

kasik96 wants to merge 1 commit into
react:mainfrom
kasik96:fix-simple-thread-safe-cache-deadlock

Conversation

@kasik96

@kasik96 kasik96 commented Oct 29, 2026 •

Copy link
Copy Markdown

Summary:

Fixes #59613.

SimpleThreadSafeCache ran the generator for a cache miss while it held its mutex. For text measurement on iOS, the generator creates an NSTextStorage, 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:

  • Added GeneratorDoesNotBlockOtherThreads: the generator waits for another thread that uses the cache. It fails without this change and passes with it.
  • Added ConcurrentMissKeepsFirstInsertedValue: another thread inserts the same key while the generator runs, and the cache keeps that value.
  • On an iPhone with iOS 27.0.1, the hang reproduced before this change and not after it.

@meta-cla

meta-cla Bot commented Oct 29, 2026

Copy link
Copy Markdown

Hi @kasik96!

Thank you for your pull request and welcome to our community.

Action Required

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

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@kasik96 kasik96 changed the title Fix iOS deadlock: run the SimpleThreadSafeCache generator outside the mutex [iOS] Fix a deadlock in text measurement: run the SimpleThreadSafeCache generator outside the lock Oct 29, 2026
@meta-cla

meta-cla Bot commented Oct 29, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 29, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Oct 29, 2026
@kasik96 kasik96 closed this Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[iOS] App hangs on iOS 27: SimpleThreadSafeCache runs text measurement while holding its lock

1 participant