Improve thread safety of MountingCoordinator#43503
Closed
rubennorte wants to merge 1 commit intofacebook:mainfrom
Closed
Improve thread safety of MountingCoordinator#43503rubennorte wants to merge 1 commit intofacebook:mainfrom
rubennorte wants to merge 1 commit intofacebook:mainfrom
Conversation
Contributor
|
This pull request was exported from Phabricator. Differential Revision: D54945100 |
rubennorte
added a commit
to rubennorte/react-native
that referenced
this pull request
Mar 15, 2024
Summary: Changelog: [internal] ## Context In the experiments to enable mount hooks on Android we saw some crashes that we couldn't reproduce or pinpoint accurately. We ran another experiment excluding part of the code in one of the variants, and we found that the problem was in this block (only crashes when `skipMountHookNotifications` is false): https://www.internalfb.com/code/fbsource/[75ebb7fc8fbe]/xplat/js/react-native-github/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp?lines=725-734 Looking more closely at the mounting coordinator code, I realized that some of the methods are not thread-safe, which is likely causing these issues. We're probably only seeing these issues on Android because we have a push model there (we call `pullTransaction` from whatever thread we're committing to, JS thread or Fabric background thread) whereas in the rest of platforms we have a pull model and we always access call `pullTransaction` from the main thread, as we do to report mounts. ## Changes 1) Make `getBaseRevision` return a copy of the revision rather than a reference. 2) Make all methods that access `baseRevision_` and `lastRevision_` thread-safe. Differential Revision: D54945100
rubennorte
added a commit
to rubennorte/react-native
that referenced
this pull request
Mar 15, 2024
Summary: Changelog: [internal] ## Context In the experiments to enable mount hooks on Android we saw some crashes that we couldn't reproduce or pinpoint accurately. We ran another experiment excluding part of the code in one of the variants, and we found that the problem was in this block (only crashes when `skipMountHookNotifications` is false): https://www.internalfb.com/code/fbsource/[75ebb7fc8fbe]/xplat/js/react-native-github/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp?lines=725-734 Looking more closely at the mounting coordinator code, I realized that some of the methods are not thread-safe, which is likely causing these issues. We're probably only seeing these issues on Android because we have a push model there (we call `pullTransaction` from whatever thread we're committing to, JS thread or Fabric background thread) whereas in the rest of platforms we have a pull model and we always access call `pullTransaction` from the main thread, as we do to report mounts. ## Changes 1) Make `getBaseRevision` return a copy of the revision rather than a reference. 2) Make all methods that access `baseRevision_` and `lastRevision_` thread-safe. Differential Revision: D54945100
2adbed9 to
71e88fb
Compare
Contributor
|
This pull request was exported from Phabricator. Differential Revision: D54945100 |
rubennorte
added a commit
to rubennorte/react-native
that referenced
this pull request
Mar 15, 2024
Summary: Changelog: [internal] ## Context In the experiments to enable mount hooks on Android we saw some crashes that we couldn't reproduce or pinpoint accurately. We ran another experiment excluding part of the code in one of the variants, and we found that the problem was in this block (only crashes when `skipMountHookNotifications` is false): https://www.internalfb.com/code/fbsource/[75ebb7fc8fbe]/xplat/js/react-native-github/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp?lines=725-734 Looking more closely at the mounting coordinator code, I realized that some of the methods are not thread-safe, which is likely causing these issues. We're probably only seeing these issues on Android because we have a push model there (we call `pullTransaction` from whatever thread we're committing to, JS thread or Fabric background thread) whereas in the rest of platforms we have a pull model and we always access call `pullTransaction` from the main thread, as we do to report mounts. ## Changes 1) Make `getBaseRevision` return a copy of the revision rather than a reference. 2) Make all methods that access `baseRevision_` and `lastRevision_` thread-safe. Differential Revision: D54945100
rubennorte
added a commit
to rubennorte/react-native
that referenced
this pull request
Mar 15, 2024
Summary: Changelog: [internal] ## Context In the experiments to enable mount hooks on Android we saw some crashes that we couldn't reproduce or pinpoint accurately. We ran another experiment excluding part of the code in one of the variants, and we found that the problem was in this block (only crashes when `skipMountHookNotifications` is false): https://www.internalfb.com/code/fbsource/[75ebb7fc8fbe]/xplat/js/react-native-github/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp?lines=725-734 Looking more closely at the mounting coordinator code, I realized that some of the methods are not thread-safe, which is likely causing these issues. We're probably only seeing these issues on Android because we have a push model there (we call `pullTransaction` from whatever thread we're committing to, JS thread or Fabric background thread) whereas in the rest of platforms we have a pull model and we always access call `pullTransaction` from the main thread, as we do to report mounts. ## Changes 1) Make `getBaseRevision` return a copy of the revision rather than a reference. 2) Make all methods that access `baseRevision_` and `lastRevision_` thread-safe. Differential Revision: D54945100
rubennorte
added a commit
to rubennorte/react-native
that referenced
this pull request
Mar 15, 2024
Summary: Changelog: [internal] ## Context In the experiments to enable mount hooks on Android we saw some crashes that we couldn't reproduce or pinpoint accurately. We ran another experiment excluding part of the code in one of the variants, and we found that the problem was in this block (only crashes when `skipMountHookNotifications` is false): https://www.internalfb.com/code/fbsource/[75ebb7fc8fbe]/xplat/js/react-native-github/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp?lines=725-734 Looking more closely at the mounting coordinator code, I realized that some of the methods are not thread-safe, which is likely causing these issues. We're probably only seeing these issues on Android because we have a push model there (we call `pullTransaction` from whatever thread we're committing to, JS thread or Fabric background thread) whereas in the rest of platforms we have a pull model and we always access call `pullTransaction` from the main thread, as we do to report mounts. ## Changes 1) Make `getBaseRevision` return a copy of the revision rather than a reference. 2) Make all methods that access `baseRevision_` and `lastRevision_` thread-safe. Differential Revision: D54945100
rubennorte
added a commit
to rubennorte/react-native
that referenced
this pull request
Mar 15, 2024
Summary: Changelog: [internal] ## Context In the experiments to enable mount hooks on Android we saw some crashes that we couldn't reproduce or pinpoint accurately. We ran another experiment excluding part of the code in one of the variants, and we found that the problem was in this block (only crashes when `skipMountHookNotifications` is false): https://github.com/facebook/react-native/blob/121b26184acbb77ff4f2360647cb322ff560b145/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp#L726-L734 Looking more closely at the mounting coordinator code, I realized that some of the methods are not thread-safe, which is likely causing these issues. ~~We're probably only seeing these issues on Android because we have a push model there (we call `pullTransaction` from whatever thread we're committing to, JS thread or Fabric background thread) whereas in the rest of platforms we have a pull model and we always access call `pullTransaction` from the main thread, as we do to report mounts.~~ This is probably fine because both cases are protected by a mutex when accessing through `ShadowTreeRegistry::visit`. But there's a case that doesn't go through it that could be causing the issues: prerendering: https://github.com/facebook/react-native/blob/121b26184acbb77ff4f2360647cb322ff560b145/packages/react-native/ReactCommon/react/renderer/scheduler/SurfaceHandler.cpp#L289 ## Changes 1) Make `getBaseRevision` return a copy of the revision rather than a reference. 2) Make all methods that access `baseRevision_` and `lastRevision_` thread-safe. Differential Revision: D54945100
71e88fb to
6dccd30
Compare
Contributor
|
This pull request was exported from Phabricator. Differential Revision: D54945100 |
Base commit: 14a7202 |
rubennorte
added a commit
to rubennorte/react-native
that referenced
this pull request
Mar 18, 2024
Summary: Changelog: [internal] ## Context In the experiments to enable mount hooks on Android we saw some crashes that we couldn't reproduce or pinpoint accurately. We ran another experiment excluding part of the code in one of the variants, and we found that the problem was in this block (only crashes when `skipMountHookNotifications` is false): https://github.com/facebook/react-native/blob/121b26184acbb77ff4f2360647cb322ff560b145/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp#L726-L734 Looking more closely at the mounting coordinator code, I realized that some of the methods are not thread-safe, which is likely causing these issues. ~~We're probably only seeing these issues on Android because we have a push model there (we call `pullTransaction` from whatever thread we're committing to, JS thread or Fabric background thread) whereas in the rest of platforms we have a pull model and we always access call `pullTransaction` from the main thread, as we do to report mounts.~~ This is probably fine because both cases are protected by a mutex when accessing through `ShadowTreeRegistry::visit`. But there's a case that doesn't go through it that could be causing the issues: prerendering: https://github.com/facebook/react-native/blob/121b26184acbb77ff4f2360647cb322ff560b145/packages/react-native/ReactCommon/react/renderer/scheduler/SurfaceHandler.cpp#L289 ## Changes 1) Make `getBaseRevision` return a copy of the revision rather than a reference. 2) Make all methods that access `baseRevision_` and `lastRevision_` thread-safe. Differential Revision: D54945100
rubennorte
added a commit
to rubennorte/react-native
that referenced
this pull request
Mar 18, 2024
Summary: Changelog: [internal] ## Context In the experiments to enable mount hooks on Android we saw some crashes that we couldn't reproduce or pinpoint accurately. We ran another experiment excluding part of the code in one of the variants, and we found that the problem was in this block (only crashes when `skipMountHookNotifications` is false): https://github.com/facebook/react-native/blob/121b26184acbb77ff4f2360647cb322ff560b145/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp#L726-L734 Looking more closely at the mounting coordinator code, I realized that some of the methods are not thread-safe, which is likely causing these issues. ~~We're probably only seeing these issues on Android because we have a push model there (we call `pullTransaction` from whatever thread we're committing to, JS thread or Fabric background thread) whereas in the rest of platforms we have a pull model and we always access call `pullTransaction` from the main thread, as we do to report mounts.~~ This is probably fine because both cases are protected by a mutex when accessing through `ShadowTreeRegistry::visit`. But there's a case that doesn't go through it that could be causing the issues: prerendering: https://github.com/facebook/react-native/blob/121b26184acbb77ff4f2360647cb322ff560b145/packages/react-native/ReactCommon/react/renderer/scheduler/SurfaceHandler.cpp#L289 ## Changes 1) Make `getBaseRevision` return a copy of the revision rather than a reference. 2) Make all methods that access `baseRevision_` and `lastRevision_` thread-safe. Differential Revision: D54945100
6dccd30 to
6213188
Compare
Contributor
|
This pull request was exported from Phabricator. Differential Revision: D54945100 |
Summary: Changelog: [internal] ## Context In the experiments to enable mount hooks on Android we saw some crashes that we couldn't reproduce or pinpoint accurately. We ran another experiment excluding part of the code in one of the variants, and we found that the problem was in this block (only crashes when `skipMountHookNotifications` is false): https://github.com/facebook/react-native/blob/121b26184acbb77ff4f2360647cb322ff560b145/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp#L726-L734 Looking more closely at the mounting coordinator code, I realized that some of the methods are not thread-safe, which is likely causing these issues. ~~We're probably only seeing these issues on Android because we have a push model there (we call `pullTransaction` from whatever thread we're committing to, JS thread or Fabric background thread) whereas in the rest of platforms we have a pull model and we always access call `pullTransaction` from the main thread, as we do to report mounts.~~ This is probably fine because both cases are protected by a mutex when accessing through `ShadowTreeRegistry::visit`. But there's a case that doesn't go through it that could be causing the issues: prerendering: https://github.com/facebook/react-native/blob/121b26184acbb77ff4f2360647cb322ff560b145/packages/react-native/ReactCommon/react/renderer/scheduler/SurfaceHandler.cpp#L289 ## Changes 1) Make `getBaseRevision` return a copy of the revision rather than a reference. 2) Make all methods that access `baseRevision_` and `lastRevision_` thread-safe. Differential Revision: D54945100
6213188 to
42505ac
Compare
Contributor
|
This pull request was exported from Phabricator. Differential Revision: D54945100 |
rubennorte
added a commit
to rubennorte/react-native
that referenced
this pull request
Mar 18, 2024
Summary: Changelog: [internal] ## Context In the experiments to enable mount hooks on Android we saw some crashes that we couldn't reproduce or pinpoint accurately. We ran another experiment excluding part of the code in one of the variants, and we found that the problem was in this block (only crashes when `skipMountHookNotifications` is false): https://github.com/facebook/react-native/blob/121b26184acbb77ff4f2360647cb322ff560b145/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp#L726-L734 Looking more closely at the mounting coordinator code, I realized that some of the methods are not thread-safe, which is likely causing these issues. ~~We're probably only seeing these issues on Android because we have a push model there (we call `pullTransaction` from whatever thread we're committing to, JS thread or Fabric background thread) whereas in the rest of platforms we have a pull model and we always access call `pullTransaction` from the main thread, as we do to report mounts.~~ This is probably fine because both cases are protected by a mutex when accessing through `ShadowTreeRegistry::visit`. But there's a case that doesn't go through it that could be causing the issues: prerendering: https://github.com/facebook/react-native/blob/121b26184acbb77ff4f2360647cb322ff560b145/packages/react-native/ReactCommon/react/renderer/scheduler/SurfaceHandler.cpp#L289 ## Changes 1) Make `getBaseRevision` return a copy of the revision rather than a reference. 2) Make all methods that access `baseRevision_` and `lastRevision_` thread-safe. Differential Revision: D54945100
Contributor
|
This pull request has been merged in ebe26c1. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
Changelog: [internal]
Context
In the experiments to enable mount hooks on Android we saw some crashes that we couldn't reproduce or pinpoint accurately.
We ran another experiment excluding part of the code in one of the variants, and we found that the problem was in this block (only crashes when
skipMountHookNotificationsis false):react-native/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp
Lines 726 to 734 in 121b261
Looking more closely at the mounting coordinator code, I realized that some of the methods are not thread-safe, which is likely causing these issues.
We're probably only seeing these issues on Android because we have a push model there (we call
pullTransactionfrom whatever thread we're committing to, JS thread or Fabric background thread) whereas in the rest of platforms we have a pull model and we always access callpullTransactionfrom the main thread, as we do to report mounts.Changes
getBaseRevisionreturn a copy of the revision rather than a reference.baseRevision_andlastRevision_thread-safe.Differential Revision: D54945100