Skip to content

Make ShadowNodeRegistry thread safe #13994

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

bood
Copy link

@bood bood commented May 16, 2017

Motivation (required)

As noted in TODO of addRootNode, ShadowNodeRegistry can be accessed by
multiple threads. Make it thread safe can avoid crashes in
UIImplementation module (e.g. tag cannot be found).

Fixes #11524 and #10755.

Example of crash stack (0.44.0):

Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'void com.facebook.react.uimanager.ReactShadowNode.addChildAt(com.facebook.react.uimanager.ReactShadowNode, int)' on a null object reference
       at com.facebook.react.uimanager.UIImplementation.setChildren(UIImplementation.java:390)
       at com.facebook.react.uimanager.UIManagerModule.setChildren(UIManagerModule.java:313)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.facebook.react.bridge.BaseJavaModule$JavaMethod.invoke(BaseJavaModule.java:368)
       at com.facebook.react.cxxbridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:138)
       at com.facebook.react.bridge.queue.NativeRunnable.run(NativeRunnable.java)
       at android.os.Handler.handleCallback(Handler.java:739)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
       at android.os.Looper.loop(Looper.java:145)
       at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:208)
       at java.lang.Thread.run(Thread.java:818)

Test Plan (required)

Crash can be re-produced by monkey test. After the fix applied, related crashes are never seen again.

As noted in `addRootNode`, ShadowNodeRegistry can be accessed by
multiple threads. Make it thread safe to avoid crashes in
`UIImplementation` module (e.g. tag cannot be found).
@facebook-github-bot facebook-github-bot added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels May 16, 2017
@yedidyak
Copy link
Contributor

Is there any news on this?

@facebook-github-bot
Copy link
Contributor

@bood I tried to find reviewers for this pull request and wanted to ping them to take another look. However, based on the blame information for the files in this pull request I couldn't find any reviewers. This sometimes happens when the files in the pull request are new or don't exist on master anymore. Is this pull request still relevant? If yes could you please rebase? In case you know who has context on this code feel free to mention them in a comment (one person is fine). Thanks for reading and hope you will continue contributing to the project.

@bood
Copy link
Author

bood commented Sep 5, 2017

Based on the blame info of the file, maybe @cjhopman or @mkonicek could review?

@stale
Copy link

stale bot commented Nov 4, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Nov 4, 2017
@stale stale bot closed this Nov 11, 2017
StepZen added a commit to studyroz/react-native that referenced this pull request Nov 16, 2017
cpirich added a commit to tracemeinc/react-native that referenced this pull request Mar 16, 2018
cpirich added a commit to tracemeinc/react-native that referenced this pull request Mar 16, 2018
landonalder pushed a commit to tracemeinc/react-native that referenced this pull request May 15, 2018
landonalder pushed a commit to tracemeinc/react-native that referenced this pull request May 15, 2018
landonalder pushed a commit to tracemeinc/react-native that referenced this pull request Aug 24, 2018
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. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Android]very dangerous thread safe issue
4 participants