Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash on HeadlessJsTaskService on old architecture #48124

Closed
wants to merge 1 commit into from

Conversation

cortinico
Copy link
Contributor

Summary:
Fixes #47592

The logic in HeadlessJsTaskService is broken. We should not check whether getReactContext is null or not.
Instead we should use the enableBridgelessArchitecture feature flag to understand if New Architecture was enabled or not.

The problem we were having is that HeadlessJsTaskService was attempting to load the New Architecture even if the user would have it turned off. The Service would then die attempting to load libappmodules.so which was correctly missing.

Changelog:
[Android] [Fixed] - Fix crash on HeadlessJsTaskService on old architecture

Differential Revision: D66826271

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Facebook Partner: Facebook Partner labels Dec 5, 2024
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D66826271

Summary:

Fixes facebook#47592

The logic in HeadlessJsTaskService is broken. We should not check whether `getReactContext` is null or not.
Instead we should use the `enableBridgelessArchitecture` feature flag to understand if New Architecture was enabled or not.

The problem we were having is that `HeadlessJsTaskService` was attempting to load the New Architecture even if the user would have it turned off. The Service would then die attempting to load `libappmodules.so` which was correctly missing.

Changelog:
[Android] [Fixed] - Fix crash on HeadlessJsTaskService on old architecture

Reviewed By: javache

Differential Revision: D66826271
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D66826271

Copy link
Contributor

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic! I integrated this locally and hit a build failure.

Suggested edit appears to fix build error and then the whole diff fixed the error I saw in my reproducer

https://github.com/mikehardy/old-arch-android-receiver-boot-crash/commit/916aa7f43236755fa4b37a30f316f17453ffe770

Thanks @cortinico

getReactNativeHost().getReactInstanceManager();

reactInstanceManager.addReactInstanceEventListener(
if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this locally, worked with this slight tweak:

Suggested change
if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) {
if (ReactFeatureFlags.enableBridgelessArchitecture) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's because we replaced ReactFeatureFlags with ReactNativeFeatureFlags on main, but on the release branch we still reference the old class

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah of course, and my reproducer was 0.76.2 still (not even .3)
I was confused how that even compiled otherwise and it was sailing right through CI! Makes sense

Okay, then given this was really just symbol motion, not really a semantic change, you've nailed it.

@christocracy
Copy link

christocracy commented Dec 5, 2024

Interesting. I think I managed to step around this bug in my own version where I borrowed the guts from HeadlessJsTaskService for my own HeadlessTaskManager and used reflection. I never had a problem with old arch on 0.76.3.

https://github.com/transistorsoft/react-native-background-geolocation/blob/ea924cb7136b6633b49caa849b1bcba68c281fe3/android/src/main/java/com/transistorsoft/rnbackgroundgeolocation/HeadlessTaskManager.java#L195-L242

So it was just getting the wires crossed between use of reactInstanceManager vs reactHost, depending on the arch, for adding / removing the ReactInstanceEventListener?

@facebook-github-bot
Copy link
Contributor

This pull request has been merged in 4560fc0.

blakef pushed a commit that referenced this pull request Dec 9, 2024
Summary:
Pull Request resolved: #48124

Fixes #47592

The logic in HeadlessJsTaskService is broken. We should not check whether `getReactContext` is null or not.
Instead we should use the `enableBridgelessArchitecture` feature flag to understand if New Architecture was enabled or not.

The problem we were having is that `HeadlessJsTaskService` was attempting to load the New Architecture even if the user would have it turned off. The Service would then die attempting to load `libappmodules.so` which was correctly missing.

Changelog:
[Android] [Fixed] - Fix crash on HeadlessJsTaskService on old architecture

Reviewed By: javache

Differential Revision: D66826271

fbshipit-source-id: 2b8418e0b01b65014cdbfd0ec2f843420a15f9db
blakef pushed a commit that referenced this pull request Dec 9, 2024
Summary:
Pull Request resolved: #48124

Fixes #47592

The logic in HeadlessJsTaskService is broken. We should not check whether `getReactContext` is null or not.
Instead we should use the `enableBridgelessArchitecture` feature flag to understand if New Architecture was enabled or not.

The problem we were having is that `HeadlessJsTaskService` was attempting to load the New Architecture even if the user would have it turned off. The Service would then die attempting to load `libappmodules.so` which was correctly missing.

Changelog:
[Android] [Fixed] - Fix crash on HeadlessJsTaskService on old architecture

Reviewed By: javache

Differential Revision: D66826271

fbshipit-source-id: 2b8418e0b01b65014cdbfd0ec2f843420a15f9db
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged This PR has been merged. p: Facebook Partner: Facebook Partner
Projects
None yet
4 participants