[iOS] Fixes race condition when setup image loader#46153
Closed
zhongwuzw wants to merge 1 commit into
Closed
Conversation
Contributor
|
@andrewdacenko has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Contributor
|
@andrewdacenko merged this pull request in 6b104bb. |
Collaborator
|
This pull request was successfully merged by @zhongwuzw in 6b104bb When will my fix make it into a release? | How to file a pick request? |
This was referenced Jun 20, 2026
meta-codesync Bot
pushed a commit
that referenced
this pull request
Jun 23, 2026
…erForData: (#57297) Summary: `imageURLLoaderForURL:` had a broken double-checked lock on `_loaders`: the outer `if (!_loaders)` guard and the `for` loop iteration both ran without `_loadersMutex`, while the assignment ran inside it. `imageDataDecoderForData:` had no lock at all on `_decoders`. Both methods write the ivar in two steps (raw list then sorted), so a concurrent reader could observe the intermediate value and iterate a concurrently-released array, crashing with `EXC_BAD_ACCESS` in `objc_release` on a GCD worker thread. Verified with a reproducer — crashes 5/5 without the fix, 0/10 with it: https://github.com/mfazekas/rn-rctimageloader-dcl-repro ## Fix Build the loader and decoder lists once in `setUp` (alongside the URL request queue), under `_setupLock` and gated by the existing `_didSetup` atomic flag. Every entry point calls `setUp` before reading the now write-once `_loaders` and `_decoders`, so a reader can never observe a half-built or concurrently-released array. This replaces the broken double-checked lock where the outer `if (!_loaders)` guard and the `for` loop iteration ran outside the mutex. ## Changelog: [iOS] [Fixed] - Fix a data race in `RCTImageLoader` loader and decoder lazy initialization that could crash with `EXC_BAD_ACCESS` ## Related Fixes #57296 See also #46115, #46153 Pull Request resolved: #57297 Reviewed By: javache Differential Revision: D109404243 Pulled By: fabriziocucci fbshipit-source-id: 359d4c70e2cbe1bc70a7e6a1dadc3e3b89c59ff4
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.
Summary:
Fixes #46115 .
Changelog:
[IOS] [FIXED] - Fixes race condition when setup image loader
Test Plan:
crash in #46115