-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
Use weak_ptr
s for AppHost
for coroutines
#16065
Conversation
See MSFT:46763065. Looks like we're in the middle of being `Refrigerate`d, we're pumping messages, and as we pump messages, we get to a `co_await` in `AppHost::_WindowInitializedHandler`. When we resume, we just try to use `this` like everything's fine but OH NO, IT'S NOT. To fix this, I'm * Adding `enable_shared_from_this` to `AppHost` * Holding the `AppHost` in a shared_ptr in WindowThread - though, this is a singular owning `shared_ptr`. This is probably ripe for other footguns, but there's little we can do about this. * whenever we `co_await` in `AppHost`, make sure we grab a weak ref first, and check it on the other side. This is another "squint and yep that's a bug" fix, that I haven't been able to verify locally. This is [allegedly](https://media.tenor.com/VQi3bktwLdIAAAAC/allegedly-supposedly.gif) about 10% of our 1.19 crashes after 3 days. Closes #16061
@@ -931,8 +931,17 @@ winrt::fire_and_forget AppHost::_peasantNotifyActivateWindow() | |||
const auto peasant = _peasant; | |||
const auto hwnd = _window->GetHandle(); | |||
|
|||
auto weakThis{ weak_from_this() }; | |||
|
|||
co_await winrt::resume_background(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to run on the BG thread in the first place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had it on a background thread so that a hung Monarch wouldn't hang a peasant process when the peasant gets activated.
I suppose these days, it's all the same process, so we could pull this one.
See MSFT:46763065. Looks like we're in the middle of being `Refrigerate`d, we're pumping messages, and as we pump messages, we get to a `co_await` in `AppHost::_WindowInitializedHandler`. When we resume, we just try to use `this` like everything's fine but OH NO, IT'S NOT. To fix this, I'm * Adding `enable_shared_from_this` to `AppHost` * Holding the `AppHost` in a shared_ptr in WindowThread - though, this is a singular owning `shared_ptr`. This is probably ripe for other footguns, but there's little we can do about this. * whenever we `co_await` in `AppHost`, make sure we grab a weak ref first, and check it on the other side. This is another "squint and yep that's a bug" fix, that I haven't been able to verify locally. This is [allegedly](https://media.tenor.com/VQi3bktwLdIAAAAC/allegedly-supposedly.gif) about 10% of our 1.19 crashes after 3 days. Closes #16061 (cherry picked from commit 8521aae) Service-Card-Id: 90731961 Service-Version: 1.18
See MSFT:46763065. Looks like we're in the middle of being `Refrigerate`d, we're pumping messages, and as we pump messages, we get to a `co_await` in `AppHost::_WindowInitializedHandler`. When we resume, we just try to use `this` like everything's fine but OH NO, IT'S NOT. To fix this, I'm * Adding `enable_shared_from_this` to `AppHost` * Holding the `AppHost` in a shared_ptr in WindowThread - though, this is a singular owning `shared_ptr`. This is probably ripe for other footguns, but there's little we can do about this. * whenever we `co_await` in `AppHost`, make sure we grab a weak ref first, and check it on the other side. This is another "squint and yep that's a bug" fix, that I haven't been able to verify locally. This is [allegedly](https://media.tenor.com/VQi3bktwLdIAAAAC/allegedly-supposedly.gif) about 10% of our 1.19 crashes after 3 days. Closes #16061 (cherry picked from commit 8521aae) Service-Card-Id: 90731962 Service-Version: 1.19
For history: > This is MSFT:46763065 internally. Dumps show this repros on 1.19 too. > > This was previously #16061 which had a theoretical fix in #16065. Looks like you're on Terminal Stable v1.18.2822.0, and https://github.com/microsoft/terminal/releases/tag/v1.18.2822.0 is supposed to have had that fix in it. Dang. > well this is embarrassing ... I never actually checked if we _still had a `_window`_. We're alive, yay! But we're still in the middle of refrigerating. So, there's no HWND anymore Attempt to fix this by actually ensuring there's a `_window` in `AppHost::_WindowInitializedHandler` Closes #16235
For history: > This is MSFT:46763065 internally. Dumps show this repros on 1.19 too. > > This was previously #16061 which had a theoretical fix in #16065. Looks like you're on Terminal Stable v1.18.2822.0, and https://github.com/microsoft/terminal/releases/tag/v1.18.2822.0 is supposed to have had that fix in it. Dang. > well this is embarrassing ... I never actually checked if we _still had a `_window`_. We're alive, yay! But we're still in the middle of refrigerating. So, there's no HWND anymore Attempt to fix this by actually ensuring there's a `_window` in `AppHost::_WindowInitializedHandler` Closes #16235 (cherry picked from commit 59dcbbe) Service-Card-Id: 91041358 Service-Version: 1.18
For history: > This is MSFT:46763065 internally. Dumps show this repros on 1.19 too. > > This was previously #16061 which had a theoretical fix in #16065. Looks like you're on Terminal Stable v1.18.2822.0, and https://github.com/microsoft/terminal/releases/tag/v1.18.2822.0 is supposed to have had that fix in it. Dang. > well this is embarrassing ... I never actually checked if we _still had a `_window`_. We're alive, yay! But we're still in the middle of refrigerating. So, there's no HWND anymore Attempt to fix this by actually ensuring there's a `_window` in `AppHost::_WindowInitializedHandler` Closes #16235 (cherry picked from commit 59dcbbe) Service-Card-Id: 91041359 Service-Version: 1.19
For history: > This is MSFT:46763065 internally. Dumps show this repros on 1.19 too. > > This was previously #16061 which had a theoretical fix in #16065. Looks like you're on Terminal Stable v1.18.2822.0, and https://github.com/microsoft/terminal/releases/tag/v1.18.2822.0 is supposed to have had that fix in it. Dang. > well this is embarrassing ... I never actually checked if we _still had a `_window`_. We're alive, yay! But we're still in the middle of refrigerating. So, there's no HWND anymore Attempt to fix this by actually ensuring there's a `_window` in `AppHost::_WindowInitializedHandler` Closes #16235 (cherry picked from commit 59dcbbe) Service-Card-Id: 91041358 Service-Version: 1.18
For history: > This is MSFT:46763065 internally. Dumps show this repros on 1.19 too. > > This was previously microsoft#16061 which had a theoretical fix in microsoft#16065. Looks like you're on Terminal Stable v1.18.2822.0, and https://github.com/microsoft/terminal/releases/tag/v1.18.2822.0 is supposed to have had that fix in it. Dang. > well this is embarrassing ... I never actually checked if we _still had a `_window`_. We're alive, yay! But we're still in the middle of refrigerating. So, there's no HWND anymore Attempt to fix this by actually ensuring there's a `_window` in `AppHost::_WindowInitializedHandler` Closes microsoft#16235
See MSFT:46763065. Looks like we're in the middle of being
Refrigerate
d, we're pumping messages, and as we pump messages, we get to aco_await
inAppHost::_WindowInitializedHandler
. When we resume, we just try to usethis
like everything's fine but OH NO, IT'S NOT.To fix this, I'm
enable_shared_from_this
toAppHost
AppHost
in a shared_ptr in WindowThreadshared_ptr
. This is probably ripe for other footguns, but there's little we can do about this.co_await
inAppHost
, make sure we grab a weak ref first, and check it on the other side.This is another "squint and yep that's a bug" fix, that I haven't been able to verify locally. This is
allegedly about 10% of our 1.19 crashes after 3 days.
Closes #16061