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

Fix a crash in _WritePseudoWindowCallback #13777

Merged
1 commit merged into from
Aug 18, 2022
Merged

Conversation

zadjii-msft
Copy link
Member

Fixes MSFT:40853556

There's a small race here. The renderer thread in ConPTY might notice the terminal is gone, call CloseOutput, and release the vt renderer, and then the window proc fires and decides to minimize/restore the window, triggering an A/V.

I'm 100% confident that this has NEVER happened to a real user. But the test labs hit it so much that it makes up ~26% of our crashes.

I haven't tested this cause again, it doesn't hit in the wild

Fixes MSFT:40853556

There's a small race here. The renderer thread in ConPTY might notice the terminal is gone, call CloseOutput, and release the vt renderer, and then the window proc fires and decides to minimize/restore the window, triggering an A/V.

I'm 100% confident that this has NEVER happened to a real user. But the test labs hit it so much that it makes up ~26% of our crashes.
@DHowett DHowett changed the title Fixes a crash in _WritePseudoWindowCallback Fixe a crash in _WritePseudoWindowCallback Aug 18, 2022
@DHowett
Copy link
Member

DHowett commented Aug 18, 2022

Could this also be MSFT:40913882?

@zadjii-msft zadjii-msft changed the title Fixe a crash in _WritePseudoWindowCallback Fix a crash in _WritePseudoWindowCallback Aug 18, 2022
@DHowett
Copy link
Member

DHowett commented Aug 18, 2022

LOL, thanks for fixing my fixe. I did the same thing to a contributor's PR this exact same week.

@zadjii-msft
Copy link
Member Author

Could this also be MSFT:40913882?

Nah, I'll reply with investigation in that bug.

// SetPseudoWindowCallback(nullptr), so that we don't just move
// the A/V race to in between checking
// _pseudoWindowMessageCallback and actually calling it.
std::lock_guard<std::mutex> lk(_shutdownLock);
Copy link
Member

Choose a reason for hiding this comment

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

FYI Since C++17 you don't need to specify template parameters anymore - they'll be automatically inferred.

@lhecker
Copy link
Member

lhecker commented Aug 18, 2022

Just from reading the diff, I don't quite get why we wouldn't have to add these guards everywhere else. What makes SetWindowVisibility so special here?

@zadjii-msft
Copy link
Member Author

Just from reading the diff, I don't quite get why we wouldn't have to add these guards everywhere else. What makes SetWindowVisibility so special here?

Presumably, this is the only bit of code that can be called from another thread in an unsafe way here. Typically everything else we were doing was always during startup or immediately on shutdown, but now we've got this pesky user32 input thread to deal with window messages that can get in here too now

@DHowett
Copy link
Member

DHowett commented Aug 18, 2022

That explanation makes sense to me!

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

ghost commented Aug 18, 2022

Hello @DHowett!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

Do note that I've been instructed to only help merge pull requests of this repository that have been opened for at least 8 hours, a condition that will be fulfilled in about 2 hours 24 minutes. No worries though, I will be back when the time is right! 😉

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@DHowett
Copy link
Member

DHowett commented Aug 18, 2022

@msftbot merge this in 5 minutes

@ghost
Copy link

ghost commented Aug 18, 2022

Hello @DHowett!

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 Thu, 18 Aug 2022 23:48:10 GMT, which is in 5 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 f58240c into main Aug 18, 2022
@ghost ghost deleted the dev/migrie/b/msft-40853556 branch August 18, 2022 23:48
DHowett pushed a commit that referenced this pull request Sep 6, 2022
Fixes MSFT:40853556

There's a small race here. The renderer thread in ConPTY might notice the terminal is gone, call CloseOutput, and release the vt renderer, and then the window proc fires and decides to minimize/restore the window, triggering an A/V.

I'm 100% confident that this has NEVER happened to a real user. But the test labs hit it so much that it makes up ~26% of our crashes.

I haven't tested this cause again, _it doesn't hit in the wild_

(cherry picked from commit f58240c)
Service-Card-Id: 85103518
Service-Version: 1.15
@ghost
Copy link

ghost commented Sep 13, 2022

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

Handy links:

@ghost
Copy link

ghost commented Sep 13, 2022

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

Handy links:

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AutoMerge Marked for automatic merge by the bot when requirements are met
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants