-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Handle connection's state #2091
Handle connection's state #2091
Conversation
Unless I happened to forget to make it draft. But otherwise, I'm making it draft. |
f6a98d9
to
92fff98
Compare
At this point I would appreciate any inital review/feedback. I don't have Azure account and I didn't find a mean to try Azure connection for free, so I can't really test the the connection. Maybe author of #1808 will be willing to participate. I'm also not sure about possible states. There might be many factors:
We shell decide which states to support and which do not. That will be important in case of network connections like ssh. We could indicate to them to user, e.g. . |
Hey @mcpiroman, I think I like the idea of having "Visual Connection States" (@zadjii-msft specifically may want to chime in about whether we'd like to have them, as I haven't thought of all the things we could do with them.) I've got some work outstanding (starting a couple weeks ago, actually, when I first submitted the closeOnExit proposal!) that does the same thing here, but uses process exit codes as the IPC mechanism. The core of the issue is that we're relying on conhost to spawn the child process, as you've correctly identified, but we can't introduce another handle to the mix to communicate that the child has failed. Ideally, we could just rely on conhost's exit code directly! Once we land #1131 we'll be starting the conhost and the child process separately, and the CreatePseudoConsole API doesn't offer support for a fourth handle. It can't be changed very much because it ships as part of Windows! 😄 Additionally, I think it should be the responsibility of the app or the control, not the connection, to react appropriately to the failing exit code. It lets us do more fine-grained but connection-generic things without putting too much logic in the connection. I'd like to avoid diverging how different connections handle failures. Features like updating the tab title are perfect for the application layer, since the app gets the final say in what ends up in the tab. The work at 7c814443 does the bare minimum here. Since you've got some good ideas in here, would you consider holding off and bringing them back to the table when those commits land? Thanks so much! |
Well, why not? I mean, it works and I'd thought we can do whatever we want with the conhost right now. Of course when we switch to official ConPTY API we'll no longer can have this 4th pipe, but there will be absolutely no need for it. And the same goes for conhost's exit code, right? The problem with exit code however is that there are 2 codes to handle - exit code from shell process and error code from
The only things that connection does is it report's current state, writes message at disconnection and proposes tab title. I think this is the right-ish way. We can't propagate exit code form connection, becouse it's not abstract enough. Azure connection does not have a process, so what exit code should it report? Thus I ended up with generic The same thing goes for message on disconnection. For conpty it might be As I've been told, connection interface is going to be exposed to 'plugins' of some sort, so that others can make their own connection types, so we need to make sure there is enough flexibility on this side. Additionally, there are requests to make the connections GUI-ish, like a window for SSH connection with address textbox and connect button, and it has to support that (if it makes sense for a terminal to have this much GUI). Connection interface has to have more polishing, but I think there is gonna be more stuff on connection side than on application. |
So, the more I've thought about this and discussed it with @zadjii-msft, the more I've felt like having the connection be in control of how it handles a failure is the right choice. I do not want to introduce another handle to conhost, because that's another resource that needs to be cleaned up, and when we move to CreatePseudoConsole we'll be in full control of the spawned shell. I do think the rest of this pull request shows some promise, and can be shaped into something that'll be great for this project. Thanks for sticking with us, @mcpiroman! |
This is superseded, but I've credited you as a coauthor in 901a1e1. Thanks so much -- we were all focused on the wrong solution until you came along with this one. |
Summary of the Pull Request
Adds ability to check if
ITerminalConnection
succeeded and indicate that to user.. Terminal now shows a message when commandline process cannot be started, or when it ends (make sure to setcloseOnExit: false
to see that). Other connections (like Azure form #1808) can add it's own specific behaviour.I'm making it draft, since I don't feel all that confident about this, as well as to add more, based on feedback. I would like to:
TL;DR
References
#2039 - This PR will provide a mean to detect graceful disconnection
PR Checklist
Detailed Description of the Pull Request / Additional comments
ITerminalConnection
that allow to get appropriate message and tab title when connection failed or is closed. In this case the message is then displayed by terminal.ConhostConnection
, through which conhost sends the creation error code (even with no error) and process handle (if created). WithConptyConnection
this will be much simpler.Validation Steps Performed
exit 123
commandline
to something that cannot be started, like__powershell.exe