-
Notifications
You must be signed in to change notification settings - Fork 9k
Avoid reentrancy issues when dropping AppHost #19296
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
Merged
Merged
Conversation
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
carlos-zamora
approved these changes
Aug 29, 2025
Member
|
Is there an issue this is linked to or that it closes? |
Member
Author
|
No, this is going off of a hunch. It's related to a slight rise in crashes as reported by watson. |
carlos-zamora
approved these changes
Aug 29, 2025
DHowett
pushed a commit
that referenced
this pull request
Sep 5, 2025
tl;dr: ~Apphost() may pump the message loop. That's no bueno. See comments in the diff. Additionally, this PR enables `_assertIsMainThread` in release to trace down mysterious crashes in those builds. **BACKPORT NOTES** I returned the `_assertIsMainThread` check to debug-only to remove the assertion risk from production builds. (cherry picked from commit 8d41ace) Service-Card-Id: PVTI_lADOAF3p4s4AxadtzgebmmE Service-Version: 1.23
DHowett
pushed a commit
that referenced
this pull request
Sep 5, 2025
tl;dr: ~Apphost() may pump the message loop. That's no bueno. See comments in the diff. Additionally, this PR enables `_assertIsMainThread` in release to trace down mysterious crashes in those builds. (cherry picked from commit 8d41ace) Service-Card-Id: PVTI_lADOAF3p4s4BBcTlzgeJeYA Service-Version: 1.24
DHowett
added a commit
that referenced
this pull request
Sep 29, 2025
The previous fix in #19296 moved the _destruction_ of AppHost into the tail end after we manipulate the `_windows` vector; however, it kept the part which calls into XAML (`Close`) before the `erase`. I suspect that we still had some reentrancy issues, where we cached an iterator before the list was modified by another window close event. That is: ```mermaid sequenceDiagram Emperor->>Emperor: Close Window Emperor->>+AppHost: Close (a) AppHost->>XAML: Close XAML-->>Emperor: pump loop Emperor->>Emperor: Close Window Emperor->>+AppHost: Close (b) AppHost->>XAML: Close XAML-->>Emperor: pump loop AppHost->>-Emperor: Closed Emperor->>Emperor: erase(b) AppHost->>-Emperor: Closed Emperor->>Emperor: erase(a) ``` Moving the `Close()` to after the `erase` ensures that there are no cached iterators that survive beyond XAML pumping the message loop. Fixes 8d41ace
DHowett
added a commit
that referenced
this pull request
Sep 30, 2025
The previous fix in #19296 moved the _destruction_ of AppHost into the tail end after we manipulate the `_windows` vector; however, it kept the part which calls into XAML (`Close`) before the `erase`. I suspect that we still had some reentrancy issues, where we cached an iterator before the list was modified by another window close event. That is: ```mermaid sequenceDiagram Emperor->>Emperor: Close Window Emperor->>+AppHost: Close (a) AppHost->>XAML: Close XAML-->>Emperor: pump loop Emperor->>Emperor: Close Window Emperor->>+AppHost: Close (b) AppHost->>XAML: Close XAML-->>Emperor: pump loop AppHost->>-Emperor: Closed Emperor->>Emperor: erase(b) AppHost->>-Emperor: Closed Emperor->>Emperor: erase(a) ``` Moving the `Close()` to after the `erase` ensures that there are no cached iterators that survive beyond XAML pumping the message loop. Fixes 8d41ace
DHowett
added a commit
that referenced
this pull request
Oct 8, 2025
The previous fix in #19296 moved the _destruction_ of AppHost into the tail end after we manipulate the `_windows` vector; however, it kept the part which calls into XAML (`Close`) before the `erase`. I suspect that we still had some reentrancy issues, where we cached an iterator before the list was modified by another window close event. That is: ```mermaid sequenceDiagram Emperor->>Emperor: Close Window Emperor->>+AppHost: Close (a) AppHost->>XAML: Close XAML-->>Emperor: pump loop Emperor->>Emperor: Close Window Emperor->>+AppHost: Close (b) AppHost->>XAML: Close XAML-->>Emperor: pump loop AppHost->>-Emperor: Closed Emperor->>Emperor: erase(b) AppHost->>-Emperor: Closed Emperor->>Emperor: erase(a) ``` Moving the `Close()` to after the `erase` ensures that there are no cached iterators that survive beyond XAML pumping the message loop. Fixes 8d41ace (cherry picked from commit 5976de1) Service-Card-Id: PVTI_lADOAF3p4s4AxadtzgfScoo Service-Version: 1.23
DHowett
added a commit
that referenced
this pull request
Oct 8, 2025
The previous fix in #19296 moved the _destruction_ of AppHost into the tail end after we manipulate the `_windows` vector; however, it kept the part which calls into XAML (`Close`) before the `erase`. I suspect that we still had some reentrancy issues, where we cached an iterator before the list was modified by another window close event. That is: ```mermaid sequenceDiagram Emperor->>Emperor: Close Window Emperor->>+AppHost: Close (a) AppHost->>XAML: Close XAML-->>Emperor: pump loop Emperor->>Emperor: Close Window Emperor->>+AppHost: Close (b) AppHost->>XAML: Close XAML-->>Emperor: pump loop AppHost->>-Emperor: Closed Emperor->>Emperor: erase(b) AppHost->>-Emperor: Closed Emperor->>Emperor: erase(a) ``` Moving the `Close()` to after the `erase` ensures that there are no cached iterators that survive beyond XAML pumping the message loop. Fixes 8d41ace (cherry picked from commit 5976de1) Service-Card-Id: PVTI_lADOAF3p4s4BBcTlzgfScpM Service-Version: 1.24
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Issue-Bug
It either shouldn't be doing this or needs an investigation.
Product-Terminal
The new Windows Terminal.
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.
tl;dr: ~Apphost() may pump the message loop.
That's no bueno. See comments in the diff.
Additionally, this PR enables
_assertIsMainThreadinrelease to trace down mysterious crashes in those builds.