Add synchronized to help prevent race condition with fresco client code #2579
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.
Thanks for submitting a PR! Please read these instructions carefully:
master
branchMotivation (required)
There is a period of time between checking if NativeLoader has been initialized, and when we try to perform
.init()
which means a race condition can occur (as mentioned in facebook/SoLoader#60). This PR provides a mechanism for client code to avoid that race condition.This change uses synchronization on the
NativeLoader
class object, and a secondary check to verify that the initialization needs to take place just before we perform it in order to reduce the window in which a race condition can happen.When combined with facebook/SoLoader#69 this will remove the race condition from the code because the initialisation inside SoLoader and inside Fresco will both be synchronized on the
NativeLoader.class
object. Without that PR in SoLoader this change will still allow fresco clients to synchronize onNativeLoader.class
in their own code around any areas which may race with this code in fresco.Test Plan (required)
This code doesn't alter the functionality of fresco, and so existing tests should provide verification that there is no operational impact.
Next Steps
Sign the CLA, if you haven't already.
Small pull requests are much easier to review and more likely to get merged. Make sure the PR does only one thing, otherwise please split it.
Make sure all tests pass on Circle CI. PRs that break tests are unlikely to be merged.
For more info, see the Contributing guide.