-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
Add support for start /B and FreeConsole #14544
Conversation
3e011e6
to
aff750d
Compare
Before merge, make sure to fill out the TBA/TBD/TBE |
And note that for the final commit message, each closed issue must be on its own line beginning with |
This comment has been minimized.
This comment has been minimized.
57fd765
to
bdab6e6
Compare
This comment has been minimized.
This comment has been minimized.
I've just restarted the PR with a rebase and a much more correct and simpler approach around the new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay Dustin explained most of this to me today and I get it, and it makes more sense now.
Timing like this is hard, and I'm glad you sorted out this wacky, wild edge case that must have just always existed in this API.
I know it's the EOY and we don't have time to write down what all is going on here, but we REALLY should better document what these changes did, and how a terminal should best use these APIs now. Just something we can refer to in 11 months when there's inevitably some new bug and we're trying to put this all back together again 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all said, a signoff
_hPC.reset(); | ||
_inPipe.reset(); | ||
|
||
_transitionToState(ConnectionState::Closing); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we used to check whether this was true because it would let us perform closing actions only once. Are these remaining actions safe to do multiple times?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it's the other way around: We used to potentially perform these actions multiple times and now we don't. This is because the old code ran past a _transitionToState()
in ConptyConnection::_ClientTerminated()
without checking the return value. So it might try to extract the _hOutputThread
and wait on it, even though the main thread might be concurrently running ConptyConnection::Close()
and trying to do the exact same thing.
The new code is more robust, because the background thread(s) don't close any system objects anymore. Only the main thread does. Technically we don't need _transitionToState()
anymore. The fact that the pipe returned ERROR_BROKEN_PIPE
is indication enough that we may exit.
Actually now that I said that I realize that our CancelSynchronousIo()
code is a bit racy. If we call it when the output thread is currently not stuck in ReadFile()
it might miss the signal to exit, which is problematic because Close()
blocks the UI thread.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in my latest commit!
b069d2b
to
6a32c28
Compare
Hello @DHowett! Because this pull request has the 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 (
|
🎉 Handy links: |
2 new ConPTY APIs were added as part of this commit:
ClosePseudoConsoleTimeout
Complements
ClosePseudoConsole
, allowing users to override theINFINITE
wait for OpenConsole to exit with any arbitrary timeout, including 0.
ConptyReleasePseudoConsole
This releases the
\Reference
handle held by theHPCON
. While it makeslaunching further PTY clients via
PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE
impossible, it does allow conhost/OpenConsole to exit naturally once all
console clients have disconnected. This makes it unnecessary to having to
monitor the exit of the spawned shell/application, just to then call
ClosePseudoConsole
, while carefully continuing to read from the outputpipe. Instead users can now just read from the output pipe until it is
closed, knowing for sure that no more data will come or clients connect.
This is especially useful in combination with
ClosePseudoConsoleTimeout
and a timeout of 0, to allow conhost/OpenConsole to exit asynchronously.
These new APIs are used to fix an array of bugs around Windows Terminal exiting
either too early or too late. They also make usage of the ConPTY API simpler in
most situations (when spawning a single application and waiting for it to exit).
Depends on #13882, #14041, #14160, #14282
Closes #4564
Closes #14416
Closes MSFT-42244182
Validation Steps Performed
FreeConsole
in a handoff'd application closes the tab ✅start /B cmd.exe
.If WT stable is the default terminal the tab closes instantly ✅
With these changes included the tab stays open with a cmd.exe prompt ✅