From c4806fada6532894e2242cf31f7145d2992e3a2b Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Mon, 6 Apr 2020 17:49:30 -0700 Subject: [PATCH] Fail silently in AppStateModule.sendEvent if CatalystInstance is not available Summary: According to our logs, 80% of these warnings are coming from AppStateModule. It's not particularly interesting or surprising that the CatalystInstance would be torn down when there's some app event, so let's stop taking up DB space with a useless message. Reviewed By: ejanzer, mdvacca Differential Revision: D20879426 fbshipit-source-id: b1182461aed4a66d82cb34bbd4b12782af6ed7b3 --- .../react/modules/appstate/AppStateModule.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/appstate/AppStateModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/appstate/AppStateModule.java index 6cfa7841df029d..396e525d5f915d 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/appstate/AppStateModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/appstate/AppStateModule.java @@ -92,11 +92,18 @@ private WritableMap createAppStateEventMap() { } private void sendEvent(String eventName, @Nullable Object data) { - ReactApplicationContext reactApplicationContext = getReactApplicationContextIfActiveOrWarn(); + ReactApplicationContext reactApplicationContext = getReactApplicationContext(); - if (reactApplicationContext != null) { - reactApplicationContext.getJSModule(RCTDeviceEventEmitter.class).emit(eventName, data); + if (reactApplicationContext == null) { + return; } + // We don't gain anything interesting from logging here, and it's an extremely common + // race condition for an AppState event to be triggered as the Catalyst instance is being + // set up or torn down. So, just fail silently here. + if (!reactApplicationContext.hasActiveCatalystInstance()) { + return; + } + reactApplicationContext.getJSModule(RCTDeviceEventEmitter.class).emit(eventName, data); } private void sendAppStateChangeEvent() {