[PR #16065] Use weak_ptrs for AppHost for coroutines #30824

Open
opened 2026-01-31 09:43:12 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/16065

State: closed
Merged: Yes


See MSFT:46763065. Looks like we're in the middle of being Refrigerated, 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 about 10% of our 1.19 crashes after 3 days.

Closes #16061

**Original Pull Request:** https://github.com/microsoft/terminal/pull/16065 **State:** closed **Merged:** Yes --- 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
claunia added the pull-request label 2026-01-31 09:43:12 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#30824