Use whether react instance is accepting calls to determine whether instance is active

Summary:
There was previously a race condition where hasActiveCatalystInstance would return true, but calling a JS module call on it would result in a crash. Now, hasActivtyCatalystInstance will only return true once the instance is actually accepting calls.

I'll follow this up with a more risky diff that gets rid of hasActiveCatalystInstance and just queues JS calls until runJSBundle is called.

Reviewed By: javache

Differential Revision: D4117374

fbshipit-source-id: 60941f68b0906a8213571305c564bfe3d053f51b
This commit is contained in:
Andy Street 2016-11-02 07:47:29 -07:00 коммит произвёл Facebook Github Bot
Родитель bdbadd1142
Коммит 6a45f05872
3 изменённых файлов: 7 добавлений и 4 удалений

Просмотреть файл

@ -40,6 +40,7 @@ public interface CatalystInstance extends MemoryPressureListener {
*/ */
void destroy(); void destroy();
boolean isDestroyed(); boolean isDestroyed();
boolean isAcceptingCalls();
/** /**
* Initialize all the native modules * Initialize all the native modules

Просмотреть файл

@ -143,7 +143,7 @@ public class ReactContext extends ContextWrapper {
} }
public boolean hasActiveCatalystInstance() { public boolean hasActiveCatalystInstance() {
return mCatalystInstance != null && !mCatalystInstance.isDestroyed(); return mCatalystInstance != null && mCatalystInstance.isAcceptingCalls();
} }
public LifecycleState getLifecycleState() { public LifecycleState getLifecycleState() {

Просмотреть файл

@ -55,9 +55,6 @@ public class CatalystInstanceImpl implements CatalystInstance {
SoLoader.loadLibrary(REACT_NATIVE_LIB); SoLoader.loadLibrary(REACT_NATIVE_LIB);
} }
private static final int BRIDGE_SETUP_TIMEOUT_MS = 30000;
private static final int LOAD_JS_BUNDLE_TIMEOUT_MS = 30000;
private static final AtomicInteger sNextInstanceIdForTrace = new AtomicInteger(1); private static final AtomicInteger sNextInstanceIdForTrace = new AtomicInteger(1);
// Access from any thread // Access from any thread
@ -247,6 +244,11 @@ public class CatalystInstanceImpl implements CatalystInstance {
return mDestroyed; return mDestroyed;
} }
@Override
public boolean isAcceptingCalls() {
return !mDestroyed && mAcceptCalls;
}
/** /**
* Initialize all the native modules * Initialize all the native modules
*/ */