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

Starting the terminal in a non-WSL shell boots a WSL distribution whose shell is set as default in settings #8285

Closed
KyleRAnderson opened this issue Nov 16, 2020 · 14 comments
Labels
Area-Settings Issues related to settings and customizability, for console or terminal Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-2 A description (P2) Product-Terminal The new Windows Terminal.
Milestone

Comments

@KyleRAnderson
Copy link

KyleRAnderson commented Nov 16, 2020

Environment

Windows build number: 10.0.19042.0
Windows Terminal version (if applicable): 1.4.3141.0

Any other software? Ubuntu 18.04 and Ubuntu WSL distros installed, the latter of which is a WSL 2 distro.

Steps to reproduce

  1. With a WSL distribution installed and its shell configured in the Windows Terminal, set that distribution's shell as the default profile in the Windows terminal settings (the distribution is usually added automatically, you should only need to modify the defaultProfile key in the settings JSON).
  2. Ensure that the WSL distribution whose shell is currently set as the default in Windows terminal is not currently running (consider using wsl --shutdown to stop all distros).
  3. Open the start menu, find the Windows Terminal application shortcut, and right click on it.
  4. Under Tasks, open any non-WSL shell such as PowerShell or cmd.
  5. Run wsl --list --verbose and observe that the WSL distribution whose shell is set to the default has been started and is now running.

Expected behavior

When starting the Windows Terminal directly to a specified profile via right clicking on the application icon and selecting one of the Tasks, the default shell is not invoked. If the default shell is a WSL distribution shell, this means not booting the WSL distribution.

Actual behavior

After starting Windows terminal directly to the powershell profile, I observed that the Ubuntu WSL distribution, whose shell is set as my default in Windows Terminal, was getting booted. The terminal would still load the Powershell profile correctly, it just starts the WSL distro even though it won't be getting used.

Settings.json

Note: I've removed the colour schemes, and I had no keybindings configured.

// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
    "$schema": "https://aka.ms/terminal-profiles-schema",
    "defaultProfile": "{2c4de342-38b7-51cf-b940-2309a097f518}",
    "profiles": {
        "defaults": {
            // Put settings here that you want to apply to all profiles
        },
        "list": [
            {
                // Make changes here to the powershell.exe profile
                "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
                "name": "Windows PowerShell",
                "commandline": "powershell.exe",
                "hidden": false
            },
            {
                // Make changes here to the cmd.exe profile
                "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
                "name": "cmd",
                "commandline": "cmd.exe",
                "hidden": false
            },
            {
                "guid": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}",
                "hidden": false,
                "name": "Ubuntu-18.04",
                "source": "Windows.Terminal.Wsl",
                "startingDirectory": "//wsl$/Ubuntu-18.04/home"
            },
            {
                "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
                "hidden": false,
                "name": "Azure Cloud Shell",
                "source": "Windows.Terminal.Azure"
            },
            {
                "guid": "{2c4de342-38b7-51cf-b940-2309a097f518}",
                "hidden": false,
                "name": "Ubuntu",
                "source": "Windows.Terminal.Wsl",
                "startingDirectory": "//wsl$/Ubuntu/home"
            },
            {
                "guid": "{00000000-0000-0000-ba54-000000000002}",
                "commandline": "%PROGRAMFILES%/git/usr/bin/bash.exe -i -l",
                "icon": "%PROGRAMFILES%/Git/mingw64/share/git/git-for-windows.ico",
                "name": "GBash",
                "startingDirectory": null,
                "colorScheme": "Tinacious Design (Dark)",
                "acrylicOpacity": 0.5,
                "useAcrylic": true
            }
        ]
    },
@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Nov 16, 2020
@DHowett
Copy link
Member

DHowett commented Nov 16, 2020

Please share a copy of your settings.json.

@DHowett DHowett added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Nov 16, 2020
@KyleRAnderson
Copy link
Author

I've updated the description @DHowett , let me know if there is anything else you'd like.

@ghost ghost 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 Nov 16, 2020
@DHowett
Copy link
Member

DHowett commented Nov 16, 2020

Thanks.

If you run wt -p {61c54bbd-c2c6-5271-96e7-009a87ff44bf} directly (from the Run dialog) after terminating your WSL instances, what happens?

When you launch Terminal via the Tasks list, and it goes to the wrong profile, what icon does it display? Does it use the settings from one profile (color scheme, font, etc.) but start an application from a different profile?

@DHowett DHowett added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something and removed Needs-Attention The core contributors need to come back around and look at this ASAP. labels Nov 16, 2020
@KyleRAnderson
Copy link
Author

KyleRAnderson commented Nov 16, 2020

Looks like I get the same behaviour when invoking it with wt -p {61c54bbd-c2c6-5271-96e7-009a87ff44bf}.

Also, to clarify @DHowett, it is going to the correct profile, using the correct icons and settings, etc. The only problem that I think exists is that it seems to be starting the WSL distro as well. It's just pointless booting of a VM only for it to be stopped automatically shortly after.

@ghost ghost 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 Nov 16, 2020
@DHowett
Copy link
Member

DHowett commented Nov 16, 2020

And if you do not set this WSL distribution as your default, it's definitely not booted?

How about if you launch Windows PowerShell outside of terminal after shutting down WSL?

WT doesn't do anything that should result in processes that are not part of a current active profile being run...

@DHowett DHowett added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something and removed Needs-Attention The core contributors need to come back around and look at this ASAP. labels Nov 16, 2020
@KyleRAnderson
Copy link
Author

KyleRAnderson commented Nov 16, 2020

When the WSL shell isn't set as my default profile and I start the app to a non-WSL profile, it doesn't start the distro. Additionally, if I set the default profile to the shell for my Ubuntu 18.04 distro, it starts that distribution instead of the Ubuntu one, so it's definitely only starting the shell that's configured as the default. This also means it's not specific to WSL 1 or WSL 2, it occurs on both.

Starting powershell or CMD from outside of Windows Terminal does not cause this issue.

@ghost ghost 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 Nov 16, 2020
@KyleRAnderson
Copy link
Author

Small note here, there seems to be a mismatch between the build number listed by [Environment]::OSVersion in PowerShell and ver in CMD.
image

I reported the one listed in PowerShell, but the version in CMD is reported when I run winver or go to Settings -> System -> About.

@DHowett
Copy link
Member

DHowett commented Nov 17, 2020

Yeah, that version number thing is annoying. PowerShell doesn't know where to find the fourth component!

Would you mind grabbing a process monitor trace? It might be enlightening, and help us see what Terminal is doing behind the scenes.

  1. Shut down WSL -- get ready to reproduce the issue
  2. Install process monitor
  3. Launch it.
  4. Configure it with the following filters in place:
    • Process Name is WindowsTerminal.exe: Include
    • Process Name is wsl.exe: Include
    • Process Name is powershell.exe: Include
    • image
  5. Hit OK
  6. Reproduce the issue! Launch terminal with a profile that is incorrectly launching WSL.
  7. Press the capture icon to stop capturing
    • image
  8. File > Save
    • image

E-mail me the PML file -- or post it here (but it will include things like your username and some details about the file layout on your machine) -- at the address on my GitHub profile.

Thanks! 😄

@DHowett DHowett added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something and removed Needs-Attention The core contributors need to come back around and look at this ASAP. labels Nov 17, 2020
@KyleRAnderson
Copy link
Author

I've gathered the logs @DHowett and have sent the email. Let me know if there's anything else that you may need.

@ghost ghost 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 Nov 17, 2020
@DHowett
Copy link
Member

DHowett commented Nov 17, 2020

I think I've got it. Thanks so much!

We create a whole TerminalSettings for the default profile to measure how big the window should be (to translate rows/columns to pixels through the renderer).
Creating one of those evaluates the starting directory for the default profile, which causes it to be checked for viability.

Since yours is //wsl$/Ubuntu/xxx, it starts up the distribution to see if that path exists. Ew.

_StartingDirectory = profile.EvaluatedStartingDirectory();

const DWORD dwFileAttributes = GetFileAttributes(evaluatedPath.get());
if ((dwFileAttributes != INVALID_FILE_ATTRIBUTES) && (WI_IsFlagSet(dwFileAttributes, FILE_ATTRIBUTE_DIRECTORY)))
{
return std::wstring(evaluatedPath.get(), numCharsInput);
}

@carlos-zamora remember how we talked about TerminalSettings proxying through to a profile? This is one issue where eagerly evaluating the profile values causes a problem.

@DHowett DHowett added Area-Settings Issues related to settings and customizability, for console or terminal Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-2 A description (P2) labels Nov 17, 2020
@DHowett DHowett added the Product-Terminal The new Windows Terminal. label Nov 17, 2020
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label Nov 17, 2020
@DHowett DHowett removed the Needs-Attention The core contributors need to come back around and look at this ASAP. label Nov 17, 2020
@KyleRAnderson
Copy link
Author

KyleRAnderson commented Nov 17, 2020 via email

@DHowett DHowett removed the Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting label Nov 20, 2020
@DHowett DHowett added this to the Terminal v2.0 milestone Nov 20, 2020
@DHowett
Copy link
Member

DHowett commented Nov 20, 2020

The fix will probably be removing EvaluatedStartingDirectory from the profile interface & evaluating it in ConPtyConnection.

@DHowett
Copy link
Member

DHowett commented Aug 2, 2021

Hey! I think we actually did fix this in 1.9. We shopped evaluating the starting directory of any profile, likely much to folks' dismay.

See #10045, which closed #9541 and #9114.

@DHowett DHowett closed this as completed Aug 2, 2021
@DHowett
Copy link
Member

DHowett commented Aug 2, 2021

/dup #9541 (sorry to dupe you to a higher number!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Settings Issues related to settings and customizability, for console or terminal Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-2 A description (P2) Product-Terminal The new Windows Terminal.
Projects
None yet
Development

No branches or pull requests

2 participants