-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
Change jsinspector back to a shared library in the CMake build #42144
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Jan 4, 2024
This pull request was exported from Phabricator. Differential Revision: D52541488 |
Base commit: 5aa425c |
…ook#42144) Summary: D51895785 changed several CMake libraries from shared to static, including `jsinspector`. This happens to be semantically incorrect in the case of `jsinspector`, as the library contains singletons which can be inadvertently duplicated due to static linking. As a result, different parts of the code can end up accessing different instances of a supposed singleton, leading to bugs. Here we revert the change to `jsinspector` (only) and add an explanatory comment to signpost this for future readers. ## More context & general principle While nothing is broken today, allowing static libraries to contain global state is brittle and breaks in surprising ways: * The upcoming diff D52231237 introduces a new dependency on `jsinspector` which builds cleanly, but causes debugging to stop working because of the duplicated singleton. * The only reason debugging currently works in the CMake build of Bridgeless is by a happy accident: the shared library `hermesinstancejni` depends on `reactnativejni` through a chain of three other libraries unrelated to debugging, and as a result, can access `reactnativejni`'s copy of `jsinspector` (see graph). {F1237835169} It seems that the safest rule of thumb, given the way React Native is currently structured, is that **singletons should live in their own shared libraries** so no call site can cause them to be duplicated through static linking. (It's reasonable to revisit this guidance if we manage to consolidate React Native into one monolithic shared library, eliminating the footgun at the source.) Changelog: [Internal] [Changed] - Change jsinspector back to a shared library in the CMake build. Reviewed By: cortinico, NickGerleman Differential Revision: D52541488
motiz88
force-pushed
the
export-D52541488
branch
from
January 4, 2024 17:30
e0089f4
to
8317800
Compare
This pull request was exported from Phabricator. Differential Revision: D52541488 |
This pull request was successfully merged by @motiz88 in 9ba3bc9. When will my fix make it into a release? | Upcoming Releases |
This pull request has been merged in 9ba3bc9. |
Othinn
pushed a commit
to Othinn/react-native
that referenced
this pull request
Jan 9, 2024
…ook#42144) Summary: Pull Request resolved: facebook#42144 D51895785 changed several CMake libraries from shared to static, including `jsinspector`. This happens to be semantically incorrect in the case of `jsinspector`, as the library contains singletons which can be inadvertently duplicated due to static linking. As a result, different parts of the code can end up accessing different instances of a supposed singleton, leading to bugs. Here we revert the change to `jsinspector` (only) and add an explanatory comment to signpost this for future readers. ## More context & general principle While nothing is broken today, allowing static libraries to contain global state is brittle and breaks in surprising ways: * The upcoming diff D52231237 introduces a new dependency on `jsinspector` which builds cleanly, but causes debugging to stop working because of the duplicated singleton. * The only reason debugging currently works in the CMake build of Bridgeless is by a happy accident: the shared library `hermesinstancejni` depends on `reactnativejni` through a chain of three other libraries unrelated to debugging, and as a result, can access `reactnativejni`'s copy of `jsinspector` (see graph). {F1237835169} It seems that the safest rule of thumb, given the way React Native is currently structured, is that **singletons should live in their own shared libraries** so no call site can cause them to be duplicated through static linking. (It's reasonable to revisit this guidance if we manage to consolidate React Native into one monolithic shared library, eliminating the footgun at the source.) Changelog: [Internal] [Changed] - Change jsinspector back to a shared library in the CMake build. Reviewed By: cortinico, NickGerleman Differential Revision: D52541488 fbshipit-source-id: 502210add0b734a9bbc470bdf38fb70a41e149a9
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary:
D51895785 changed several CMake libraries from shared to static, including
jsinspector
. This happens to be semantically incorrect in the case ofjsinspector
, as the library contains singletons which can be inadvertently duplicated due to static linking. As a result, different parts of the code can end up accessing different instances of the supposed singleton, leading to bugs.Here we revert the change to
jsinspector
(only) and add an explanatory comment to signpost this for future readers.More context & general principle
While nothing is broken today, allowing static libraries to contain global state is brittle and breaks in surprising ways:
jsinspector
which builds cleanly, but causes debugging to stop working because of the duplicated singleton.hermesinstancejni
depends onreactnativejni
through a chain of three other libraries unrelated to debugging, and as a result, can accessreactnativejni
's copy ofjsinspector
(see graph).{F1237835169}
It seems that the safest rule of thumb, given the way React Native is currently structured, is that singletons should live in their own shared libraries so no call site can cause them to be duplicated through static linking. (It's reasonable to revisit this guidance if we manage to consolidate React Native into one monolithic shared library, eliminating the footgun at the source.)
Changelog:
[Internal] [Changed] - Change jsinspector back to a shared library in the CMake build.
Differential Revision: D52541488