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

Refactor how connection restarting is handled #14548

Closed

Conversation

zadjii-msft
Copy link
Member

Admittedly, this is a lot of annoying plumbing.

We didn't love that a connection could transition back in the state diagram, from Closed -> Start. That felt wrong. To remedy this, we're going to allow the ControlCore to re-create connections, all on its own. This builds on a lot of work that was originally done for Process Model v2 (#5000), and was originally slated to be merged in #12938.

Basically, all the properties for a Connection are stashed already in a ConnectionState object. We're gonna take that, and stash the info in the ControlCore. When the control wants to restart the connection, it just uses that to rebuild a new one.

Cleanup from #14060

Closes #14327

@ghost ghost added Area-CodeHealth Issues related to code cleanliness, linting, rules, warnings, errors, static analysis, etc. Area-TerminalConnection Issues pertaining to the terminal<->backend connection interface Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal. Severity-Blocking We won't ship a release like this! No-siree. labels Dec 13, 2022
@github-actions

This comment has been minimized.

Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

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

Okay, some big questions. I don't love how we're becoming more stringly-typed but perhaps it offers us some heretofore unobserved opportunities...

src/cascadia/TerminalControl/TermControl.idl Outdated Show resolved Hide resolved
src/cascadia/TerminalControl/TermControl.h Outdated Show resolved Hide resolved
src/cascadia/TerminalControl/ControlCore.h Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/TerminalPage.cpp Outdated Show resolved Hide resolved
if (auto conpty{ existingConnection.try_as<ConptyConnection>() })
{
connectionInfo = TerminalConnection::ConnectionInformation(winrt::name_of<TerminalConnection::ConptyConnection>(),
conpty.ToSettings());
Copy link
Member

Choose a reason for hiding this comment

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

It feels like ConptyConnection (or, any connection) should be able to produce a fully-formed ConnectionInformation itself, without the consumer needing to know about its classname

Copy link
Member Author

Choose a reason for hiding this comment

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

That... might? be able to be done. Not sure it's immediately relevant here (in the defterm context). But I guess it could be ConptyConnection::CreateConnectionInfo(settings...) -> ConnectionInfo, and have it fill in its own name.

@@ -2721,10 +2744,15 @@ namespace winrt::TerminalApp::implementation
if (bothAltsPressed)
{
std::tie(connection, debugConnection) = OpenDebugTapConnection(connection);
// Debug Tap connections aren't really restartable. The
Copy link
Member

Choose a reason for hiding this comment

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

so what happens if you do restart one?

Copy link
Member Author

Choose a reason for hiding this comment

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

You can restart the underlying connection, but not the debugtap-ness of it. The debug spew just stops, but the real pane gets restarted.

src/cascadia/TerminalControl/ControlCore.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalControl/ControlCore.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalControl/ControlCore.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalConnection/ConnectionInformation.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/TerminalPage.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/TerminalPage.cpp Show resolved Hide resolved
src/cascadia/TerminalApp/TerminalPage.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/TerminalPage.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/TerminalPage.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/TerminalPage.cpp Show resolved Hide resolved
Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

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

14/15

@@ -35,6 +35,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation
winrt::fire_and_forget UpdateControlSettings(Control::IControlSettings settings, Control::IControlAppearance unfocusedAppearance);
IControlSettings Settings() const;

TerminalConnection::ConnectionInformation ConnectionInfo();
Copy link
Member

Choose a reason for hiding this comment

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

I don't totally understand why TerminalPage can't just make a totally new connection out of nothing - I find it so weird that TermControl now has a Connection (which we gave it) and a ConnectionInfo (which we used to make the Connection, and then also gave it). How would a public user of TermControl's public API even know what to do with all of these members?

Copy link
Member

Choose a reason for hiding this comment

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

I don't love the pattern of storing effectively random app data on random other classes, you know? We did the same for Profile (and pushed it all the way down to the Core)...

// connection's settings. This'll cause conpty to restart
// the connection at the current place in the buffer.
_ConnectionInfo.Settings().Insert(L"inheritCursor", Windows::Foundation::PropertyValue::CreateBoolean(true));
auto c = TerminalConnection::ConnectionInformation::CreateConnection(_ConnectionInfo);
Copy link
Member

Choose a reason for hiding this comment

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

okay, I see, but I still don't love it. "Sometimes the connection comes from the app and sometimes TermControl spontaneously creates life and seeds it onto an empty planet makes its own connection".

if (ch == Enter)
// If we have a connection info with which to try and re-create the
// connection, then let's try doing that on Enter
if (_ConnectionInfo != nullptr)
Copy link
Member

Choose a reason for hiding this comment

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

I guess this puts us in a really weird position, where ConptyConnection is responsible for printing out the "press ^D to restart" message, but TermControl is ultimately responsible for handling it.

But at the same time, this means that users of other connections (#4661) won't be told that ^D/Enter are options... but they MIGHT be? If they can be reconstructed via ConnectionInfo?

{
if (_connection)
{
_connectionOutputEventRevoker.revoke();
Copy link
Member

Choose a reason for hiding this comment

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

overwriting _connectionStateChangedRevoker later should revoke it automatically, without you needing to check this

// Starting Directory - alas, we don't know that for a defterm connection.
// The Core might be able to fill it in, if the client app ever tells the
// Terminal.
Windows::Foundation::Collections::ValueSet ConptyConnection::GetDeftermSettings()
Copy link
Member

Choose a reason for hiding this comment

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

for my own understanding
We have to use this in the magical scenario where we got a connection created out of nowhere and we had no way to inform TerminalPage what settings it started with?

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Apr 20, 2023
@zadjii-msft
Copy link
Member Author

Closed in favor of #15240

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs-Attention The core contributors need to come back around and look at this ASAP. and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Apr 26, 2023
DHowett pushed a commit that referenced this pull request Apr 28, 2023
A different take on #14548.

> We didn't love that a connection could transition back in the state
diagram, from Closed -> Start. That felt wrong. To remedy this, we're
going to allow the ControlCore to...

ASK the app to restart its connection. This is a much more sensible
approach, than leaving the ConnectionInfo in the core and having the
core do the restart itself. That's mental.

Cleanup from #14060

Closes #14327

Obsoletes #14548
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-CodeHealth Issues related to code cleanliness, linting, rules, warnings, errors, static analysis, etc. Area-TerminalConnection Issues pertaining to the terminal<->backend connection interface Issue-Task It's a feature request, but it doesn't really need a major design. Needs-Attention The core contributors need to come back around and look at this ASAP. Product-Terminal The new Windows Terminal. Severity-Blocking We won't ship a release like this! No-siree.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Code Health: follow ups from connection restarting
5 participants