Skip to content
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

Call UpdatePatternLocations from a background thread #13758

Merged
1 commit merged into from
Aug 16, 2022

Conversation

lhecker
Copy link
Member

@lhecker lhecker commented Aug 16, 2022

We have a number of theories why #12607 is happening, one of which is that
some GPU drivers somehow rely on Win32 messages or similar which we process
on the main thread. If we then try to acquire the console lock on the main
thread, while the GPU-driver thread itself is holding that lock, we've got
ourselves a deadlock. This PR makes this less likely by running the repeat
offender UpdatePatternLocations on a background thread instead.
We have a number of other locations which acquire the console lock on the
main thread and a thorough bug fix must be done in a different way.

Validation Steps Performed

  • After pasting an URL it gets underlined on hover ✅

@lhecker lhecker added this to the Terminal v1.16 milestone Aug 16, 2022
@lhecker lhecker added Issue-Bug It either shouldn't be doing this or needs an investigation. Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Product-Terminal The new Windows Terminal. Priority-1 A description (P1) labels Aug 16, 2022
UpdatePatternLocationsInterval,
[weakThis = get_weak()]() {
if (auto core{ weakThis.get() }; !core->_IsClosing())
if (auto core{ weakThis.get() })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can we be sure now that the control isn't tearing down?

Copy link
Member Author

@lhecker lhecker Aug 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We simply can't. After all, _IsClosing isn't a mutex which would prevent the main thread from closing under us while we're running on the background thread.
Thankfully, Terminal::_InvalidatePatternTree doesn't seem to depend on any UI state.

@lhecker
Copy link
Member Author

lhecker commented Aug 16, 2022

Thinking about it, this is actually a good change in general. Reading the Terminal code it seems like updating the pattern locations involves nothing the main thread would be interested in, so there was no reason to ever do this on the main thread in the first place (AFAICS).

@lhecker
Copy link
Member Author

lhecker commented Aug 16, 2022

@msftbot merge this in 15 minutes

@ghost ghost added the AutoMerge Marked for automatic merge by the bot when requirements are met label Aug 16, 2022
@ghost
Copy link

ghost commented Aug 16, 2022

Hello @lhecker!

Because you've given me some instructions on how to help merge this pull request, I'll be modifying my merge approach. Here's how I understand your requirements for merging this pull request:

  • I won't merge this pull request until after the UTC date Tue, 16 Aug 2022 18:29:34 GMT, which is in 15 minutes

If this doesn't seem right to you, you can tell me to cancel these instructions and use the auto-merge policy that has been configured for this repository. Try telling me "forget everything I just told you".

@ghost ghost merged commit 23e4d31 into main Aug 16, 2022
@ghost ghost deleted the dev/lhecker/12607-workaround branch August 16, 2022 18:30
@ghost
Copy link

ghost commented Aug 17, 2022

🎉Windows Terminal v1.14.228 has been released which incorporates this pull request.:tada:

Handy links:

@ghost
Copy link

ghost commented Aug 17, 2022

🎉Windows Terminal Preview v1.15.228 has been released which incorporates this pull request.:tada:

Handy links:

PKRoma pushed a commit to PKRoma/Terminal that referenced this pull request Oct 15, 2022
We have a number of theories why microsoft#12607 is happening, one of which is that
some GPU drivers somehow rely on Win32 messages or similar which we process
on the main thread. If we then try to acquire the console lock on the main
thread, while the GPU-driver thread itself is holding that lock, we've got
ourselves a deadlock. This PR makes this less likely by running the repeat
offender `UpdatePatternLocations` on a background thread instead.
We have a number of other locations which acquire the console lock on the
main thread and a thorough bug fix must be done in a different way.

## Validation Steps Performed
* After pasting an URL it gets underlined on hover ✅

(cherry picked from commit 23e4d31)
Service-Card-Id: 85033019
Service-Version: 1.15
PKRoma pushed a commit to PKRoma/Terminal that referenced this pull request Oct 15, 2022
We have a number of theories why microsoft#12607 is happening, one of which is that
some GPU drivers somehow rely on Win32 messages or similar which we process
on the main thread. If we then try to acquire the console lock on the main
thread, while the GPU-driver thread itself is holding that lock, we've got
ourselves a deadlock. This PR makes this less likely by running the repeat
offender `UpdatePatternLocations` on a background thread instead.
We have a number of other locations which acquire the console lock on the
main thread and a thorough bug fix must be done in a different way.

* After pasting an URL it gets underlined on hover ✅

(cherry picked from commit 23e4d31)
Service-Card-Id: 85033018
Service-Version: 1.14
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants