Android: After the app reloads, we're stuck with a dead thread because of SingleThreadAsserter
See original GitHub issueEnvironment
Environment: OS: macOS Sierra 10.12.6 Node: 8.4.0 Yarn: 1.5.1 npm: 5.3.0 Watchman: 4.7.0 Xcode: Xcode 9.2 Build version 9C40b Android Studio: 3.0 AI-171.4443003
Packages: (wanted => installed) react: 16.2.0 => 16.2.0 react-native: 0.53.0 => 0.53.0
Expected Behavior
I would expect the SingleThreadAsserter
to clear the mThread
value after the app reloads, so that a new thread can be used on every assertion from that point in.
Actual Behavior
Instead, the SingleThreadAsserter
locks to the thread it was created with, so when the app reloads, and that thread dies we’re stuck with a dead thread, which causes all subsequent assertions to fail.
Almost every uiManager
method requires that assertion, so that’s a big issue.
Steps to Reproduce
Here’s a repo that suffers from that issue. https://github.com/SudoPlz/react-native-synchronous-list
- Download
- cd RNExample
- yarn install
- Run the android project.
All works well until you reload. After the reload we get:
FATAL EXCEPTION: main
Process: com.rnexample, PID: 8519
java.lang.AssertionError
at com.facebook.infer.annotation.Assertions.assertCondition(Assertions.java:66)
at com.facebook.react.common.SingleThreadAsserter.assertNow(SingleThreadAsserter.java:27)
at com.facebook.react.uimanager.ShadowNodeRegistry.getNode(ShadowNodeRegistry.java:67)
at com.facebook.react.uimanager.UIImplementation.createView(UIImplementation.java:278)
at com.facebook.react.uimanager.UIManagerModule.createView(UIManagerModule.java:364)
at com.sudoplz.rnsynchronouslistmanager.Views.SyncRootView$3.run(SyncRootView.java:172)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (5 by maintainers)
Got it, always requesting the current react application context fixed the issue, thank you so much @janicduplessis !
I had a quick look at the code and is it possible that you are holding on to an old instance of
ReactApplicationContext
? I think you should useReactInstanceManager##getCurrentReactContext
to make sure you have the proper one like the code inReactRootView
does.You could override https://github.com/facebook/react-native/blob/2b6599e9c8b393bb20bf04e206d8982f587e75dd/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java#L356 to get the
ReactInstanceManager
since it is private inReactRootView
sadly.