[PR #15328] (WIP) Improve pointer safety around coroutines #30592

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

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

State: closed
Merged: No


I went through random parts of Windows Terminal trying to fix as many
theoretical (and practical) bugs I could find. My initial idea was that
one of the biggest sources of easily detectable bugs are coroutines
which do not properly hold onto their this pointer strongly across
suspension points. This commit fixes maybe about 3/4ths of those bugs.
Other bugs, like nullptr crashes, are significantly harder to spot.

To do so I've removed resume_foreground/background from as many
coroutines as I could and then added assertions that data only got
accessed on the UI threads. This allowed me to remove most coroutines.
Next, I've added get_weak/strong() pointers to the remaining ones.

As a drive by it also improves the following:

  • QuitAllRequestedArgs technically isn't needed, because there was no
    reason for _saveWindowLayouts() to yield to a background thread in
    the first place.

Validation Steps Performed

  • TBA (I'll go through all changes and assemble a list of functionalities these affect)
**Original Pull Request:** https://github.com/microsoft/terminal/pull/15328 **State:** closed **Merged:** No --- I went through random parts of Windows Terminal trying to fix as many theoretical (and practical) bugs I could find. My initial idea was that one of the biggest sources of easily detectable bugs are coroutines which do not properly hold onto their `this` pointer strongly across suspension points. This commit fixes maybe about 3/4ths of those bugs. Other bugs, like `nullptr` crashes, are significantly harder to spot. To do so I've removed `resume_foreground/background` from as many coroutines as I could and then added assertions that data only got accessed on the UI threads. This allowed me to remove most coroutines. Next, I've added `get_weak/strong()` pointers to the remaining ones. As a drive by it also improves the following: * `QuitAllRequestedArgs` technically isn't needed, because there was no reason for `_saveWindowLayouts()` to yield to a background thread in the first place. ## Validation Steps Performed * TBA (I'll go through all changes and assemble a list of functionalities these affect)
claunia added the pull-request label 2026-01-31 09:41:45 +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#30592