question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android: After the app reloads, we're stuck with a dead thread because of SingleThreadAsserter

See original GitHub issue

Environment

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.

https://github.com/facebook/react-native/blob/26684cf3adf4094eb6c405d345a75bf8c7c0bf88/ReactAndroid/src/main/java/com/facebook/react/common/SingleThreadAsserter.java#L23

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

  1. Download
  2. cd RNExample
  3. yarn install
  4. 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:closed
  • Created 6 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
SudoPlzcommented, Aug 30, 2018

Got it, always requesting the current react application context fixed the issue, thank you so much @janicduplessis !

0reactions
janicduplessiscommented, Aug 30, 2018

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 use ReactInstanceManager##getCurrentReactContext to make sure you have the proper one like the code in ReactRootView 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 in ReactRootView sadly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android Service (In its own thread) dies when app is killed ...
If an Application is actually killed (vs an Activity simply being destroyed) everything in that process dies. A service that is supposed to ......
Read more >
Processes and threads overview - Android Developers
This document discusses how processes and threads work in an Android application. Processes. By default, all components of the same application ...
Read more >
Slack's having issues with notifications and loading threads ...
Slack says it's “identified the cause” of its threading issues, ... the app also booted me out of the Threads screen when I...
Read more >
How to Handle Died Threads due to Uncaught Exceptions in ...
In concurrent applications a thread might fail and die due to uncaught runtime exceptions even without noticing since the application may continue to...
Read more >
Top 10 Most Common Mistakes That Android Developers Make
Killing one won't free the resources used by the others. This Android programming tutorial recommends the proper use of fragments to make your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found