Skip to content
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

Enforced thread safety on UIImplementation methods that mutate the shadowNodeRegistry #20025

Closed
wants to merge 2 commits into from

Conversation

SudoPlz
Copy link
Contributor

@SudoPlz SudoPlz commented Jul 4, 2018

Fixes: #17178

Changelog

[ANDROID] [Fixes] - UIImplementation: Now enforcing atomic mutation of the shadowNodeRegistry

@facebook-github-bot facebook-github-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 Jul 4, 2018
@pull-bot
Copy link

pull-bot commented Jul 4, 2018

Messages
📖 📋 Missing Summary - Can you add a Summary? To do so, add a "## Summary" section to your PR description. This is a good place to explain the motivation for making this change.
📖 📋 Missing Test Plan - Can you add a Test Plan? To do so, add a "## Test Plan" section to your PR description. A Test Plan lets us know how these changes were tested.
📖

📋 Changelog Format - Did you include a Changelog? A changelog entry has the following format: [CATEGORY] [TYPE] - Message.

CATEGORY may be:
  • General
  • iOS
  • Android

TYPE may be:

  • Added, for new features.
  • Changed, for changes in existing functionality.
  • Deprecated, for soon-to-be removed features.
  • Removed, for now removed features.
  • Fixed, for any bug fixes.
  • Security, in case of vulnerabilities.

MESSAGE may answer "what and why" on a feature level. Use this to briefly tell React Native users about notable changes.

Generated by 🚫 dangerJS against 6bfe5dd

@react-native-bot react-native-bot added Missing Test Plan This PR appears to be missing a test plan. ✅Release Notes labels Jul 4, 2018
@SudoPlz
Copy link
Contributor Author

SudoPlz commented Jul 5, 2018

I didn't change anything on iOS, not sure what's wrong with those tests :/

@xkrsz
Copy link

xkrsz commented Jul 10, 2018

Those two tests are broken currently, don't bother yourself.

@xkrsz
Copy link

xkrsz commented Jul 10, 2018

I've found that your fix also resolves a couple of errors we're experiencing in production (react-native v0.47.1). Here's the list:

  • Attempt to invoke virtual method 'void com.facebook.react.uimanager.ReactShadowNode.addChildAt(com.facebook.react.uimanager.ReactShadowNode, int)' on a null object reference
  • Attempt to invoke virtual method 'void com.facebook.react.uimanager.ReactShadowNode.addChildAt(com.facebook.react.uimanager.ReactShadowNode, int)' on a null object reference
  • Attempt to invoke virtual method 'com.facebook.react.uimanager.ThemedReactContext com.facebook.react.uimanager.ReactShadowNode.getThemedContext()' on a null object reference
  • IllegalViewOperationExceptioncom.facebook.react.uimanager.UIImplementation in setChildren: Trying to add unknown view tag: 292

Big thumbs up, hope this will be merged soon.

@xkrsz
Copy link

xkrsz commented Jul 10, 2018

Fixes #20078

@patrickkempff
Copy link
Contributor

patrickkempff commented Jul 10, 2018

Can confirm that this PR fixes this exception we had with the native Android ViewPager in production (0.55.3):

Fatal Exception: com.facebook.react.uimanager.IllegalViewOperationException
Trying to add unknown view tag: 3391

@SudoPlz
Copy link
Contributor Author

SudoPlz commented Jul 11, 2018

Good. Let's hope to hear from someone in Facebook soon.

@janicduplessis
Copy link
Contributor

Do you know which method is accessed from a different thread? I'd rather avoid locking by making sure calls are made from a single thread (unless we really have to).

cc @mdvacca

@SudoPlz
Copy link
Contributor Author

SudoPlz commented Jul 15, 2018

Anything that mutates the cssNode sparse array list is unsafe

private final SparseArray<ReactShadowNode> mTagsToCSSNodes;

@LorienHW
Copy link

LorienHW commented Aug 2, 2018

really eager to see this merged! using react-native-navigation we see these crashes in production constantly, thanks so much for this!

@facebook-github-bot
Copy link
Contributor

@SudoPlz 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.

@SudoPlz
Copy link
Contributor Author

SudoPlz commented Aug 3, 2018

Hmm maybe @mkonicek can take a look?

@krishanmarco
Copy link

Any news on this?
Is there anything that can be done to speed up the process to merge this?

@Aaang
Copy link

Aaang commented Sep 3, 2018

Hi everyone,

we're also seeing many crashes on production caused by the mentioned issue(s) that this PR would fix, therefore we'd love to see this PR being reviewed and merged, so we don't have to (for the first time in 2 years) use a fork instead of the official RN version or add a custom UIImplementation handler as a workaround only to fix it.
Is there anything we can do to support you?

Since this PR didn't get much attention lately, maybe @sophiebits could take a look?
Any progress is very much appreciated!

@alimek
Copy link

alimek commented Sep 3, 2018

same issues in my app on production :(

@matthargett
Copy link
Contributor

@SudoPlz can you respond to my review comments? I was waiting on that before lobbying other contributors. FWIW, RN Windows has a similar fix.

Copy link
Contributor

@matthargett matthargett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the locks be finer-grained? It seems like there are more things in the synchronized() block than need to be.

@levynir
Copy link

levynir commented Oct 18, 2018

Hey, any update on this?

@alimek
Copy link

alimek commented Oct 18, 2018

maybe its worth ask: @SudoPlz and @matthargett :-)

@SudoPlz
Copy link
Contributor Author

SudoPlz commented Oct 18, 2018

I have no idea what the future of this PR is, the Facebook team is heavily working on Fabric right now, so I'd love their 2 cents on wether they'll be accepting this or not, or if they have another way of fixing it.

@SudoPlz
Copy link
Contributor Author

SudoPlz commented Oct 18, 2018

By the way someone made a replication repo here https://github.com/Frank1234/RNViewPager
(looks like you can steadily replicate the crash - unless you use this PR - steadily by tapping that button a couple of times)

I haven't tested it yet though.

@levynir
Copy link

levynir commented Oct 21, 2018

@matthargett , could you guys take this on please? Clearly the failed tests have nothing to do with @SudoPlz 's changes and this is causing production crashes for many users. Would be happy to help if there is anything I can do, but I suspect this is a bit out of my league.

@kelset
Copy link
Contributor

kelset commented Nov 30, 2018

uhm the Detox fail doesn't seem to be related to this, I think I've seen it in other PRs too - I feel it may be something broken in master.

@hramos
Copy link
Contributor

hramos commented Dec 11, 2018

Would you mind adding a test plan to your PR?

@SudoPlz
Copy link
Contributor Author

SudoPlz commented Dec 11, 2018

@hramos not sure how to do that? Any examples?

@kelset
Copy link
Contributor

kelset commented Dec 12, 2018

@SudoPlz you can check the label https://github.com/facebook/react-native/pulls?q=is%3Apr+is%3Aopen+sort%3Aupdated-desc+label%3A%22%E2%9C%85Test+Plan%22, but basically it's at least a description of how to repro and how to ensure that there is a way to verify that the fix actually does the fix :)

Copy link
Contributor

@shergin shergin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing that! ❤️
Could you please fix some nits?

  • @mdvacca Should bless this before landing.

@cpojer
Copy link
Contributor

cpojer commented Feb 21, 2019

@SudoPlz could you rebase your PR and apply the changes requested by @shergin so we can merge this?

@SudoPlz
Copy link
Contributor Author

SudoPlz commented Feb 21, 2019

Rebased, and removed the comments.

@SudoPlz
Copy link
Contributor Author

SudoPlz commented Feb 21, 2019

@shergin @cpojer all set.

@The0racle
Copy link

Seeing crashes on my app as well related to this. Were these issues fixed somewhere else?

Thanks!

@cpojer
Copy link
Contributor

cpojer commented Mar 27, 2019

Oh wow, I'm sorry I missed this last time. Seems like it is outdated again. Would you mind rebasing it once more? Then I'll make sure we can get it reviewed and merged.

@SudoPlz
Copy link
Contributor Author

SudoPlz commented Mar 27, 2019

@cpojer I've just rebased again, that should do the trick.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shergin is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @SudoPlz in f149426.

When will my fix make it into a release? | Upcoming Releases

@react-native-bot react-native-bot added the Merged This PR has been merged. label Mar 27, 2019
@LorienHW
Copy link

yaaaas!

@mhdtouban
Copy link

mhdtouban commented Jul 12, 2019

@cpojer We are on RN v 0.59 and we still getting this issue, have you verified the solution ? in which version it was merged?

@jstheoriginal
Copy link
Contributor

@mhdtouban based on the tags of the merge commit, it looks like it's only in 0.60 and later.

v0.60.4 v0.60.3 v0.60.2 v0.60.1 v0.60.0 v0.60.0-rc.3 v0.60.0-rc.2 v0.60.0-rc.1 v0.60.0-rc.0 latest 0.60.2

@ikesyo
Copy link
Contributor

ikesyo commented Sep 20, 2019

This was actually backported and released in v0.59.5: https://github.com/react-native-community/releases/blob/master/CHANGELOG.md#v0595

Enforced thread safety on UIImplementation methods that mutate the shadowNodeRegistry (f5a318 by @SudoPlz)

facebook-github-bot pushed a commit that referenced this pull request Nov 9, 2020
Summary:
Base sync before adding Flight files.

This sync includes the following changes:
- **[454c2211c](facebook/react@454c2211c )**: Refactor SchedulerHostConfigs ([#20025](facebook/react#20025)) //<Ricky>//
- **[56e9feead](facebook/react@56e9feead )**: Remove Blocks ([#20138](facebook/react#20138)) //<Sebastian Markbåge>//
- **[3fbd47b86](facebook/react@3fbd47b86 )**: Serialize pending server components by reference (lazy component) ([#20137](facebook/react#20137)) //<Sebastian Markbåge>//
- **[930ce7c15](facebook/react@930ce7c15 )**: Allow values to be encoded by "reference" to a value rather than the value itself ([#20136](facebook/react#20136)) //<Sebastian Markbåge>//
- **[39eb6d176](facebook/react@39eb6d176 )**: Rename ([#20134](facebook/react#20134)) //<Sebastian Markbåge>//
- **[ffd842335](facebook/react@ffd842335 )**: [Flight] Add support for Module References in transport protocol ([#20121](facebook/react#20121)) //<Sebastian Markbåge>//
- **[343d7a4a7](facebook/react@343d7a4a7 )**: Fast Refresh: Don't block DevTools commit hook ([#20129](facebook/react#20129)) //<Brian Vaughn>//
- **[779a472b0](facebook/react@779a472b0 )**: Prevent inlining into recursive commit functions ([#20105](facebook/react#20105)) //<Andrew Clark>//
- **[25b18d31c](facebook/react@25b18d31c )**: Traverse commit phase effects iteratively ([#20094](facebook/react#20094)) //<Andrew Clark>//

Changelog:
[General][Changed] - React Native sync for revisions 4e5d7fa...454c221

Reviewed By: rickhanlonii

Differential Revision: D24698701

fbshipit-source-id: dfaf692b1051150355dece1657764a484b7ae603
@ngioldasis
Copy link

Hi,
I'm experiencing a "similar" error with the stack-trace below.

My environment is:

  • react-native: 0.66.3
  • react: 17.0.2
  • react-navigation: 6.0.6

The error occurs occasionally on android device and emulator, while navigating from one screen to another in a stack navigator.

Unfortunately, I cannot reproduce the error.

Any idea?

unknown:ReactNative: Exception in native call com.facebook.react.uimanager.IllegalViewOperationException: Trying to update non-existent view with tag 3203 at com.facebook.react.uimanager.UIImplementation.updateView(UIImplementation.java:287) at com.facebook.react.uimanager.UIManagerModule.updateView(UIManagerModule.java:519) at java.lang.reflect.Method.invoke(Native Method) at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372) at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:188) at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method) at android.os.Handler.handleCallback(Handler.java:900) at android.os.Handler.dispatchMessage(Handler.java:103) at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27) at android.os.Looper.loop(Looper.java:219) at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:226) at java.lang.Thread.run(Thread.java:929)

@pke
Copy link

pke commented Feb 14, 2022

We are also getting this error still in production only:

com.facebook.react.uimanager.IllegalViewOperationException: Trying to remove a view index above child count 2 view tag: 3175
detail: View tag:3175 View Type:class com.facebook.react.views.view.ReactViewGroup
children(2): [
6957,7837,
],
indicesToRemove(1): [
2,
],
tagsToDelete(1): [
13989,
]
at com.facebook.react.uimanager.NativeViewHierarchyManager.manageChildren(NativeViewHierarchyManager.java
  at com.facebook.react.uimanager.UIViewOperationQueue$ManageChildrenOperation.execute (UIViewOperationQueue.java:217)
  at com.facebook.react.uimanager.UIViewOperationQueue$1.run (UIViewOperationQueue.java:915)
  at com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches (UIViewOperationQueue.java:1026)
  at com.facebook.react.uimanager.UIViewOperationQueue.access$2600 (UIViewOperationQueue.java:47)
  at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded (UIViewOperationQueue.java:1086)
  at com.facebook.react.uimanager.GuardedFrameCallback.doFrame (GuardedFrameCallback.java:29)
  at com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame (ReactChoreographer.java:175)
  at com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame (ChoreographerCompat.java:85)
  at android.view.Choreographer$CallbackRecord.run (Choreographer.java:972)
  at android.view.Choreographer.doCallbacks (Choreographer.java:797)
  at android.view.Choreographer.doFrame (Choreographer.java:728)
  at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:959)
  at android.os.Handler.handleCallback (Handler.java:938)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loop (Looper.java:230)
  at android.app.ActivityThread.main (ActivityThread.java:7700)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:612)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:997)

Not reproducible sadly.

@mannoeu
Copy link

mannoeu commented Oct 2, 2024

same here

react-native 0.73.4

com.facebook.react.uimanager.IllegalViewOperationException: Trying to resolve view with tag 4049 which doesn't exist
        at com.facebook.react.uimanager.NativeViewHierarchyManager.resolveView(NativeViewHierarchyManager.java:102)
        at com.facebook.react.uimanager.UIManagerModule.resolveView(UIManagerModule.java:870)
        at com.mrousavy.camera.react.CameraViewModule$findCameraView$$inlined$runOnUiThreadAndWait$1.run(runOnUiThread.kt:40)
        at android.os.Handler.handleCallback(Handler.java:914)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:241)
        at android.app.ActivityThread.main(ActivityThread.java:7582)
        at java.lang.reflect.Method.invoke(Method.java:-2)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941)

@ngioldasis
Copy link

I do have the same issue on 0.72.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Missing Test Plan This PR appears to be missing a test plan. Platform: Android Android applications.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

com.facebook.react.uimanager.IllegalViewOperationException