[PR #7575] Destruct ConptyConnection on a background thread #26944

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

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

State: closed
Merged: Yes


This commit leverages C++/WinRT's final_release extension point to
pull the final destruction of ConptyConnection off onto a background
thread.

We've been seeing some deadlocks during teardown where the output thread
(holding the last owning reference to the connection) was trying to
destruct the threadpool wait while the threadpool wait was
simultaneously running its callback and waiting for the output thread to
terminate. It turns out that trying to release a threadpool wait while
it's running a callback that's blocked on you will absolutely result in
a deadlock.

Fixes #7392.

**Original Pull Request:** https://github.com/microsoft/terminal/pull/7575 **State:** closed **Merged:** Yes --- This commit leverages C++/WinRT's final_release [extension point] to pull the final destruction of ConptyConnection off onto a background thread. We've been seeing some deadlocks during teardown where the output thread (holding the last owning reference to the connection) was trying to destruct the threadpool wait while the threadpool wait was simultaneously running its callback and waiting for the output thread to terminate. It turns out that trying to release a threadpool wait while it's running a callback that's blocked on you will absolutely result in a deadlock. Fixes #7392. [extension point]: https://devblogs.microsoft.com/oldnewthing/20191018-00/?p=103010
claunia added the pull-request label 2026-01-31 09:19:03 +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#26944