Skip to content

Commit

Permalink
Add atomic registerSegment method to test
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Lulu Wu authored and facebook-github-bot committed Nov 3, 2022
1 parent 4f3ca8f commit f207cfd
Showing 1 changed file with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit f207cfd

Please sign in to comment.