Skip to content

Commit

Permalink
[Fabric] Fix hang on shutdown when JS instance failed to start (#12867)
Browse files Browse the repository at this point in the history
* Fix hang on shutdown when JS instance failed to start

* Change files

* dont wrap the ManualResetEvent in another shared_ptr

* use unique_ptr since there is only one ref

* fix
  • Loading branch information
acoates-ms authored Mar 26, 2024
1 parent f83c158 commit b99ccd7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "[Fabric] Fix hang on shutdown when JS instance failed to start",
"packageName": "react-native-windows",
"email": "30809111+acoates-ms@users.noreply.github.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,13 @@ void CompositionRootView::UpdateRootViewInternal() noexcept {
}
}

struct AutoMRE {
~AutoMRE() {
mre.Set();
}
Mso::ManualResetEvent mre;
};

void CompositionRootView::UninitRootView() noexcept {
if (!m_isInitialized) {
return;
Expand All @@ -411,8 +418,10 @@ void CompositionRootView::UninitRootView() noexcept {
// This is needed to ensure that the unmount JS logic is completed before the the instance is shutdown during
// instance destruction. Aligns with similar code in ReactInstanceWin::DetachRootView for paper Future: Instead this
// method should return a Promise, which should be resolved when the JS logic is complete.
// The task will auto set the event on destruction to ensure that the event is set if the JS Queue has already been
// shutdown
Mso::ManualResetEvent mre;
m_context.JSDispatcher().Post([&]() { mre.Set(); });
m_context.JSDispatcher().Post([autoMRE = std::make_unique<AutoMRE>(AutoMRE{mre})]() {});
mre.Wait();

// Paper version gives the JS thread time to finish executing - Is this needed?
Expand Down

0 comments on commit b99ccd7

Please sign in to comment.