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 crash on exit introduced in ac265aa #10042

Merged
1 commit merged into from
May 11, 2021
Merged

Fix crash on exit introduced in ac265aa #10042

1 commit merged into from
May 11, 2021

Conversation

lhecker
Copy link
Member

@lhecker lhecker commented May 5, 2021

Summary of the Pull Request

ControlCore::AttachUiaEngine receives a IRenderEngine as a raw pointer,
which TermControl owns. We must ensure that we first destroy the
ControlCore before the UiaEngine instance (both owned by TermControl).
Otherwise a deallocated IRenderEngine is accessed when
ControlCore calls Renderer::TriggerTeardown.

References

This crash was introduced in #10031.

PR Checklist

  • I work here
  • Tests added/passed

Validation Steps Performed

  • Run accevent.exe to cause a UiaEngine to be attached to a TermControl.
  • Close the current tab
  • Ensured no crashes occur

@lhecker lhecker requested a review from DHowett May 5, 2021 23:00
// teardown, to avoid the render thread being deadlocked. The
// renderer may be waiting to acquire the terminal lock, while
// we're waiting for the renderer to finish.
auto lock = _terminal->LockForWriting();
Copy link
Member

Choose a reason for hiding this comment

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

(we don't need to lock any longer?)

Copy link
Member

Choose a reason for hiding this comment

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

The core thesis of the fix earlier was that we needed to lock to steal away the renderer. I know the rest of the fix pulled the code out of Close so that _renderer continued to exist ... so perhaps this is not a problem

Copy link
Member Author

Choose a reason for hiding this comment

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

This line was only added because j4james (not tagging to not spam them) was experiencing crashes. But as we now know we can fix it much more thoroughly by ensuring that no one is using the renderer anymore.
Originally there was no LockForWriting before calling TriggerTeardown. Assuming this was correct back then, we won't need it anymore now.

@lhecker lhecker force-pushed the dev/lhecker/fix-exit-crash branch from aa157e5 to 5988fce Compare May 6, 2021 00:15
ControlCore::AttachUiaEngine receives a IRenderEngine as a raw pointer,
which TermControl owns. We must ensure that we first destroy the
ControlCore before the UiaEngine instance (both owned by TermControl).
Otherwise a deallocated IRenderEngine is accessed when
ControlCore calls Renderer::TriggerTeardown.
@lhecker lhecker force-pushed the dev/lhecker/fix-exit-crash branch from 5988fce to f470f49 Compare May 6, 2021 00:45
@DHowett DHowett added zPreview-Service-Queued-1.13 A floating label that tracks the current Preview version for servicing purposes. zStable-Service-Queued-1.12 A floating label that tracks the current Stable version for servicing purposes. labels May 11, 2021
@DHowett DHowett added the Needs-Second It's a PR that needs another sign-off label May 11, 2021
Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

whoops, forgot that I never hit ✔️

@carlos-zamora
Copy link
Member

@msftbot merge this in 20 hours

@ghost ghost added the AutoMerge Marked for automatic merge by the bot when requirements are met label May 11, 2021
@ghost
Copy link

ghost commented May 11, 2021

Hello @carlos-zamora!

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 Wed, 12 May 2021 18:54:19 GMT, which is in 20 hours

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".

@DHowett
Copy link
Member

DHowett commented May 11, 2021

@msftbot merge this in 1 minutes

@ghost
Copy link

ghost commented May 11, 2021

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 Tue, 11 May 2021 23:02:11 GMT, which is in 1 minute

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 43040ef into main May 11, 2021
@ghost ghost deleted the dev/lhecker/fix-exit-crash branch May 11, 2021 23:03
@DHowett DHowett removed the zStable-Service-Queued-1.12 A floating label that tracks the current Stable version for servicing purposes. label May 14, 2021
DHowett pushed a commit that referenced this pull request May 14, 2021
ControlCore::AttachUiaEngine receives a IRenderEngine as a raw pointer,
which TermControl owns. We must ensure that we first destroy the
ControlCore before the UiaEngine instance (both owned by TermControl).
Otherwise a deallocated IRenderEngine is accessed when
ControlCore calls Renderer::TriggerTeardown.

This crash was introduced in #10031.

* [x] I work here
* [x] Tests added/passed

* Run accevent.exe to cause a UiaEngine to be attached to a TermControl.
* Close the current tab
* Ensured no crashes occur

(cherry picked from commit 43040ef)
DHowett pushed a commit that referenced this pull request May 14, 2021
ControlCore::AttachUiaEngine receives a IRenderEngine as a raw pointer,
which TermControl owns. We must ensure that we first destroy the
ControlCore before the UiaEngine instance (both owned by TermControl).
Otherwise a deallocated IRenderEngine is accessed when
ControlCore calls Renderer::TriggerTeardown.

This crash was introduced in #10031.

* [x] I work here
* [x] Tests added/passed

* Run accevent.exe to cause a UiaEngine to be attached to a TermControl.
* Close the current tab
* Ensured no crashes occur

(cherry picked from commit 43040ef)
(cherry picked from commit ad45139)
@ghost
Copy link

ghost commented May 25, 2021

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

Handy links:

@ghost
Copy link

ghost commented May 25, 2021

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

Handy links:

@DHowett DHowett removed the zPreview-Service-Queued-1.13 A floating label that tracks the current Preview version for servicing purposes. label May 28, 2021
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 Needs-Second It's a PR that needs another sign-off
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants