From f207cfddf37c01b5ff2c2f53b4d44a4cc7ad2484 Mon Sep 17 00:00:00 2001 From: Lulu Wu Date: Wed, 2 Nov 2022 21:01:53 -0700 Subject: [PATCH] Add atomic registerSegment method to test Summary: In the top js errors there are 2 mids related to segment fetching: - requireForFacebook.js:unknownModuleError (https://www.internalfb.com/logview/details/facebook_android_javascripterrors/ba11461526aff8a6842401b35b02f5a4), 11.64 K vs. 524 - asyncRequire.js:verifySegment (https://www.internalfb.com/logview/details/facebook_android_javascripterrors/5452ba893b8d9ba8e97e070cf6976b65) 5.39 K vs. 180 Both errors will result in surface not loading. A lot of traces have logs similar with the following: ```11-01 19:57:51.166 27735 7626 W fb4a.BridgelessReact: registerSegment(segmentId = "1090", path = "/data/data/com.facebook.katana/app_overtheair/resources/412137089/414433453/hbc-seg-1090__DELIM__main.jsbundle") 11-01 19:57:51.167 27735 7445 I ReactNativeJS: Module 39122 in segment 0 doesn not exist moduleDefiner 11-01 19:57:51.171 27735 7445 E ReactNativeJS: Error: Requiring unknown module "39122"., js build: 414433453 11-01 19:57:51.175 27735 7445 E ReactNativeJS: Error: Segment meta module is not setup properly. Details: segmentId = 1090, metaModule === undefined 11-01 19:57:51.175 27735 7445 E ReactNativeJS: 11-01 19:57:51.175 27735 7445 E ReactNativeJS: This error is located at: ``` RegisterSegment lives through 3 threads while in bridge there are only 2 threads involved (native & JS): - Native thread, log printed (fb4a.BridgelessReact: registerSegment...) - Background thread: no log, added in this diff (Finish registerSegment...) - JS thread: logs not printed, should print logs here: https://www.internalfb.com/code/fbsource/[60521987354ed1ef9a0d10bafc60db3c25302ab4]/xplat/ReactNative/venice/ReactInstance.cpp?lines=308-330 Since the JS thread logs aren't printed and there are segment errors right after calling registerSegemnt, I think registerSegment is not done. It could be caused by: - ReactInstance being null, I added logs in background thread to verify (Finish registerSegment...) since dispatching to background thread relies on non-nullable ReactInstance. - Work on JS thread hasn't been executed when trying to use/verify the segment. I added atomic method ```registerSegmentAtomic``` to make sure JS thread is blocked until segment is fully registered. ```registerSegmentAtomic``` will be tested behind gating added in D40917444. Changelog: [Android][Changed] - Add feature flag enableAtomicRegisterSegment Reviewed By: RSNara Differential Revision: D40921759 fbshipit-source-id: 84221aa81f0c549f931a4847b154187299639ef4 --- .../main/java/com/facebook/react/config/ReactFeatureFlags.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java b/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java index f837171c994..a4cf989ca75 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java +++ b/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java @@ -120,4 +120,7 @@ public class ReactFeatureFlags { /** Temporary flag to allow execution of mount items up to 15ms earlier than normal. */ public static boolean enableEarlyScheduledMountItemExecution = false; + + // TODO (T136375139): Remove this once finish testing + public static boolean enableAtomicRegisterSegment = false; }