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

Make conhost act in VtIo mode earlier in startup #15298

Merged
merged 2 commits into from
May 10, 2023

Conversation

zadjii-msft
Copy link
Member

@zadjii-msft zadjii-msft commented May 5, 2023

We need to act like a ConPTY just a little earlier in startup. My relevant notes start here: #15245 (comment).

Basically, we'd create the first screen buffer with 9001 rows, because it would be created before VtIo would be in a state to say "yes, we're a conpty". Then, if a CLI app emits an entire screenful of text before the terminal has a chance to resize the conpty, then the conpty will explode during _DoLineFeed. That method is absolutely not expecting the buffer to get resized (and the old text buffer deallocated).

Instead, this will treat the console as in ConPty mode as soon as VtIo::Initialize is called (this is during ConsoleCreateIoThread, which is right at the end of ConsoleEstablishHandoff, which is before the API server starts to process the client connect message). THEORETICALLY, VtIo could Initialize then fail to create objects in CreateIoHandlers (which is what we used to treat as the moment that we were in conpty mode). However, if we do fail out of CreateIoHandlers, then the console itself will fail to start up, and just die. So I don't think that's needed.

This fixes #15245. I think this is PROBABLY also the solution to #14512, but I'm not gonna explicitly mark closed. We'll loop back on it.

TODO

  • I want to audit the uses of CONSOLE_INFORMATION::IsInVtIoMode before I commit to this.

This is a theory. I want to audit the uses of `CONSOLE_INFORMATION::IsInVtIoMode` before I commit to this.

But I think this:
* fixes #15245
* fixes #14512

Because basically, we'd create the first screen buffer with 9001 rows, because it would be created _before_ VtIo would be in a state to say "yes, we're a conpty"
@microsoft-github-policy-service microsoft-github-policy-service bot added Issue-Bug It either shouldn't be doing this or needs an investigation. Area-DefApp Product-Conhost For issues in the Console codebase Product-Conpty For console issues specifically related to conpty Product-Terminal The new Windows Terminal. Severity-Blocking We won't ship a release like this! No-siree. Severity-Crash Crashes are real bad news. labels May 5, 2023
@zadjii-msft

This comment was marked as resolved.

@zadjii-msft
Copy link
Member Author

Note for @DHowett: thinking that we shouldn't immediately service this, at least until we have some 1.18 selfhost that suggests it's safe

@@ -230,7 +230,7 @@ VtIo::VtIo() :

bool VtIo::IsUsingVt() const
{
return _objectsCreated;
return _initialized || _objectsCreated;
Copy link
Member

Choose a reason for hiding this comment

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

Aside from EnableConptyModeForTests, it seems like _objectsCreated isn't needed anymore. Remove it?

@DHowett
Copy link
Member

DHowett commented May 8, 2023

My only concern is that... _DoLineFeed happens under the console lock, there should be no way to replace the buffer WHILE it is running..?

@zadjii-msft
Copy link
Member Author

My only concern is that... _DoLineFeed happens under the console lock, there should be no way to replace the buffer WHILE it is running..?

#15245 (comment)

@DHowett
Copy link
Member

DHowett commented May 8, 2023

My only concern is that... _DoLineFeed happens under the console lock, there should be no way to replace the buffer WHILE it is running..?

#15245 (comment)

oop

@zadjii-msft zadjii-msft merged commit 6ad8cd0 into main May 10, 2023
@zadjii-msft zadjii-msft deleted the dev/migrie/b/15245-defterm-crashes-openconsole branch May 10, 2023 12:16
PKRoma pushed a commit to PKRoma/Terminal that referenced this pull request May 12, 2023
DHowett pushed a commit that referenced this pull request Nov 28, 2023
We need to act like a ConPTY just a little earlier in startup. My relevant notes start here: #15245 (comment).

Basically, we'd create the first screen buffer with 9001 rows, because it would be created _before_ VtIo would be in a state to say "yes, we're a conpty". Then, if a CLI app emits an entire screenful of text _before_ the terminal has a chance to resize the conpty, then the conpty will explode during `_DoLineFeed`. That method is absolutely not expecting the buffer to get resized (and the old text buffer deallocated).

Instead, this will treat the console as in ConPty mode as soon as `VtIo::Initialize` is called (this is during `ConsoleCreateIoThread`, which is right at the end of `ConsoleEstablishHandoff`, which is before the API server starts to process the client connect message).  THEORETICALLY, `VtIo` could `Initialize` then fail to create objects in `CreateIoHandlers` (which is what we used to treat as the moment that we were in conpty mode). However, if we do fail out of `CreateIoHandlers`, then the console itself will fail to start up, and just die. So I don't think that's needed.

This fixes #15245. I think this is PROBABLY also the solution to #14512, but I'm not gonna explicitly mark closed. We'll loop back on it.

(cherry picked from commit 6ad8cd0)
Service-Card-Id: 89112504
Service-Version: 1.17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-DefApp Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Conhost For issues in the Console codebase Product-Conpty For console issues specifically related to conpty Product-Terminal The new Windows Terminal. Severity-Blocking We won't ship a release like this! No-siree. Severity-Crash Crashes are real bad news. zBugBash-Consider
Projects
Status: Cherry Picked
Development

Successfully merging this pull request may close these issues.

Crash when defterm handoff'ing a bat file?
3 participants