terminal icon indicating copy to clipboard operation
terminal copied to clipboard

Windows Terminal as default Console Host + Resume Issues

Open ForbiddenEra opened this issue 2 years ago • 3 comments

Windows Terminal version

1.19.3172.0 (Windows Store Preview)

Windows build number

10.0.19045.3570

Other Software

C:\Users\forbiddenera>ssh -V OpenSSH_for_Windows_8.1p1, LibreSSL 3.0.2

C:\Users\forbiddenera>wsl -v WSL version: 2.0.9.0 (pretty sure I originally installed w/Add/Remove Features but it now shows up as installed on Windows Store) Kernel version: 5.15.133.1-1 WSLg version: 1.0.59 MSRDC version: 1.2.4677 Direct3D version: 1.611.1-81528511 DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp Windows version: 10.0.19045.3570

Steps to reproduce

I've experienced more than a few issues that seem to be related to using Windows Terminal as the default console host and especially relate to the resumption features.

Here, I'll detail the two main issues I seem to experience the most often:

  1. Opening a command prompt often (but I think not always) opens a separate process and will resume a previous session, even if that session has already been resumed (and is even still open). This issue also happens in other cases, such as when any program opens/spawns a console window itself for whatever reason. 1.1 - Have a Windows Terminal session running; for me to reproduce just now, I had one window open with multiple (SSH, WSL2) tabs. This session and it's tabs, in my case, was restored from a previous session when first opening Windows Terminal. You will need to have a previous session to resume from to reproduce. 1.2 - Try to open a command prompt in some typical ways such as Start->Run->cmd.exe or Win+X->Command Prompt (Note: I am of course aware that Command Prompt (Admin) opens a separate Admin-owned process) 1.3 - The command prompt opens as expected but also creates a separate Windows Terminal process (which on it's own wouldn't be terrible if not ideal) and also opens a second window containing all the tabs from the resumed session.

  2. This one may seem a little application specific but could affect many applications beyond the case where I ran into it. In my case, the application was the Furmark 2 beta but I can imagine this being a huge issue for anyone doing any sort of crypto mining as those are basically always console apps and are probably more likely to cause crashes/restarts than most apps AND are more likely to be left unattended. 2.1 - Run Furmark 2 (or probably any app that launches a console) and then have your system crash (in my case, I'm using a spare lower wattage PSU while my main one is RMA'd and Furmark triggered OCP while running causing the system to shutdown) or forcefully shutdown/reboot. 2.2 - System reboots, login and Windows Terminal restores it's session. 2.3 - Furmark 2 now starts running again, potentially causing a crash and endless boot loop unless the user intervenes.

I have Windows Terminal set to launch on startup and resume it's session and this is a lovely feature as my work entails having like 10+ terminals open all the time and having to re-open, re-connect and re-arrange all the windows and tabs anytime I reboot (or am forced to reboot) is a huge pain and having this feature (plus browsers and other apps nowadays) has actually made me a lot less reboot-averse; thus disabling it isn't really ideal.

The second issue I have also reported to the Furmark team so they can potentially work around it but that doesn't account for all other console software that could potentially crash causing a reboot.

The first issue, I've had instances where I've literally ended up with like 4-5 Windows Terminal instances all resuming with their 10+ tabs each, in fact it's triggered security warnings when it does it and suddenly I've got like 10 SSH terminals open to one host as it's determined well outside what ML deems normal usage.

Expected Behavior

  1. A session shouldn't resume in when a second Windows Terminal process launches after it's been resumed already.
  2. A session shouldn't resume at least a tab/app which caused a crash/reboot of Windows Terminal or the system in general. I'm not sure how well this could be implemented but I don't think many would object to Windows Terminal prompting and asking/warning if Windows Terminal had not been closed properly (due to Windows Terminal crashing, Windows crashing, power outage, random reboot, whatever) or even not resuming the session after a crash and/or perhaps not launching on login/system startup after a system crash.

Actual Behavior

I hit Win+X->Command Prompt and got a new Window with the command prompt and then also a second window which was duplicated the session I already had open in Windows Terminal: image

ForbiddenEra avatar Jan 13 '24 11:01 ForbiddenEra

I've also had occurrences since my post where when an app launches a console program and it does the resume where I get two new extra windows with the same tabs. And I just had an instance where I closed the console program (after closing the extra windows when said program first opened) and closing it caused even more windows to appear!

ForbiddenEra avatar Jan 15 '24 12:01 ForbiddenEra

I need to go dedupe the set of

  • #16487
  • #16557
  • #16561
issue Windows? DefTerm? Restore prev session Launch on startup? issues?
#16487 10 true true true ❌ launch on boot restores normally, then defterm also restores?
#16487 10 true true true ✅ seemingly works fine?
#16557 10 ? true true ❌ launch on boot restores normally, then {{a second launch, unsure if defterm}} also restores?
#16561 10 ? ? (probably) true ❌ launch on boot restores double of the session

zadjii-msft avatar Jan 31 '24 22:01 zadjii-msft

This is getting a tiny bit nuts...I just rebooted with two terminals Windows opened before reboot, one with a single tab, the other with like 4 tabs...

After I reboot, I get this: image image

That's 31 shell tabs/instances! Should only be 5!

Let me know if I can provide any useful details/logs/settings/whatever.

ForbiddenEra avatar Feb 04 '24 10:02 ForbiddenEra

Okay after caching these threads all in, I'm gonna go dupe this to /dup #16487. Seems like in all these cases, a session restore during a Windows resume seems to leave the terminal in a state where it doesn't realize it needs to restore. As to why, I'm not sure yet. I'm guessing that if you do the "Identify Window" command, from the command palette, in each window, at least two have the same ID.

To help flesh-out the variables at play here: do you have the Terminal configured as the default terminal emulator in the Windows settings?

zadjii-msft avatar Feb 08 '24 12:02 zadjii-msft

Okay after caching these threads all in, I'm gonna go dupe this to /dup #16487. Seems like in all these cases, a session restore during a Windows resume seems to leave the terminal in a state where it doesn't realize it needs to restore. As to why, I'm not sure yet. I'm guessing that if you do the "Identify Window" command, from the command palette, in each window, at least two have the same ID.

To help flesh-out the variables at play here: do you have the Terminal configured as the default terminal emulator in the Windows settings?

@zadjii-msft :: Yes, I do, thought I mentioned that above. And it doesn't only happen when resuming Windows; it happens sometimes when something causes a terminal to open, such as a program opening a terminal app.

Beyond answering your question though, I guess I'll track the issue in the other thread :)

ForbiddenEra avatar Feb 14 '24 16:02 ForbiddenEra