terminal icon indicating copy to clipboard operation
terminal copied to clipboard

Windows Terminal keeps forgetting/can't find my default WSL Ubuntu profile

Open DuncanSimon opened this issue 6 years ago • 41 comments

Environment

Windows build number: Version 1909 (OS Build 18363.900)
Windows Terminal version (if applicable): 1.0.1811.0

Any other software?
Ubuntu 18.04 LTS for WSL

Steps to reproduce

  1. WSL and Ubuntu 18.04 are already installed and configured.
  2. Install Windows Terminal from the Microsoft Store.
  3. Upon first installation, it will automatically pick up the Ubuntu profile
  4. Set the Ubuntu profile as default in settings.json
  5. After e.g. restarting the pc, Windows Terminal can no longer find the default profile and does not list Ubuntu in the drop-down

Expected behavior

Ubuntu 18.04 for WSL to persist as the default profile that Windows Terminal uses when it launches.

Actual behavior

After e.g. restarting the pc, Windows Terminal can no longer find the default profile and does not list Ubuntu in the drop-down. The following error occurs when launching Windows Terminal: " Encountered errors while loading user settings Could not find your default profile in your list of profiles - using the first profile. Check to make sure the "defaultProfile" matches the GUID of one of your profiles. "

The defaultProfile guid matches that of the Ubuntu profile. JSON for Ubuntu profile:

           {
                "guid": "{some_guid}",
                "hidden": false,
                "name": "Ubuntu-18.04",
                "source": "Windows.Terminal.Wsl",
		"startingDirectory": "//wsl$/Ubuntu-18.04/home/my_username"
            }

DuncanSimon avatar Jul 16 '20 09:07 DuncanSimon

If you relaunch terminal some time later, does the Ubuntu profile show back up?

DHowett avatar Jul 16 '20 17:07 DHowett

No, it seems to lose track of it forever.

DuncanSimon avatar Jul 16 '20 17:07 DuncanSimon

Can you share the output of wsl -l -v --all? If that fails, can you just run wsl -l?

DHowett avatar Jul 16 '20 17:07 DHowett

It didn't like the -v flag, but wsl -l gives:

Windows Subsystem for Linux Distributions:
Ubuntu-18.04 (Default)

DuncanSimon avatar Jul 16 '20 17:07 DuncanSimon

Wow, this is really unexpected. Can you share your entire settings.json?

DHowett avatar Jul 16 '20 17:07 DHowett

I wonder if it's something to do with "source": "Windows.Terminal.Wsl", because when I comment this line out, it does seem to launch into Ubuntu. Although it's not quite right, because it doesn't set all the colour/font scheme settings I have, doesn't have the Linux icon, and doesn't like me passing in a starting directory.

Here's the full settings.json:

// This file was initially generated by Windows Terminal 1.0.1811.0
// It should still be usable in newer versions, but newer versions might have additional
// settings, help text, or changes that you will not see unless you clear this file
// and let us generate a new one for you.

// 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": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}",

    // You can add more global application settings here.
    // To learn more about global settings, visit https://aka.ms/terminal-global-settings

    // If enabled, selections are automatically copied to your clipboard.
    "copyOnSelect": false,

    // If enabled, formatted data is also copied to your clipboard
    "copyFormatting": false,

    // A profile specifies a command to execute paired with information about how it should look and feel.
    // Each one of them will appear in the 'New Tab' dropdown,
    //   and can be invoked from the commandline with `wt.exe -p xxx`
    // To learn more about profiles, visit https://aka.ms/terminal-profile-settings
    "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": "Command Prompt",
                "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/<user>",
		"colorScheme": "Ubuntu",
		"fontFace": "DejaVuSansMono"
            },
            {
                "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
                "hidden": false,
                "name": "Azure Cloud Shell",
                "source": "Windows.Terminal.Azure"
            }
        ]
    },

    // Add custom color schemes to this array.
    // To learn more about color schemes, visit https://aka.ms/terminal-color-schemes
    "schemes": [
		{
			"name": "Ubuntu",
			
			"background": "#300a24",
			"foreground": "#eeeeec",
			
			"black": "#2e3436",
			"red": "#cc0000",
			"green": "#4e9a06",
			"yellow": "#c4a000",
			"blue": "#3465a4",
			"purple": "#75507b",
			"cyan": "#06989a",
			"white": "#d3d7cf",
			"brightBlack": "#555753",
			"brightRed": "#ef2929",
			"brightGreen": "#8ae234",
			"brightYellow": "#fce94f",
			"brightBlue": "#729fcf",
			"brightPurple": "#ad7fa8",
			"brightCyan": "#34e2e2",
			"brightWhite": "#eeeeec"
			
		}
	],

    // Add custom keybindings to this array.
    // To unbind a key combination from your defaults.json, set the command to "unbound".
    // To learn more about keybindings, visit https://aka.ms/terminal-keybindings
    "keybindings":
    [
        // Copy and paste are bound to Ctrl+Shift+C and Ctrl+Shift+V in your defaults.json.
        // These two lines additionally bind them to Ctrl+C and Ctrl+V.
        // To learn more about selection, visit https://aka.ms/terminal-selection
        { "command": {"action": "copy", "singleLine": false }, "keys": "ctrl+c" },
        { "command": "paste", "keys": "ctrl+v" },

        // Press Ctrl+Shift+F to open the search box
        { "command": "find", "keys": "ctrl+shift+f" },

        // Press Alt+Shift+D to open a new pane.
        // - "split": "auto" makes this pane open in the direction that provides the most surface area.
        // - "splitMode": "duplicate" makes the new pane use the focused pane's profile.
        // To learn more about panes, visit https://aka.ms/terminal-panes
        { "command": { "action": "splitPane", "split": "auto", "splitMode": "duplicate" }, "keys": "alt+shift+d" }
    ]
}

DuncanSimon avatar Jul 16 '20 17:07 DuncanSimon

Interesting. So, when you comment out source two things happen.

  • Terminal stops deleting the profile
  • Terminal launches cmd.exe (lol), not wsl

When a profile has a source and a guid, Terminal queries to make sure that the source (in this case, "wsl") still thinks it exists. When Terminal asks, unfortunately, WSL reports that there aren't any installed distributions.

Are you running WT at a different user than your desktop session?

DHowett avatar Jul 16 '20 17:07 DHowett

Yeah that's basically what happens. I'm running WT as the same user. It's so odd because whenever I do a fresh install of WT it always works fine, and then at some point it just breaks.

DuncanSimon avatar Jul 16 '20 17:07 DuncanSimon

Is there some hidden guid that my Ubuntu installation has that causes a conflict?

DuncanSimon avatar Jul 16 '20 17:07 DuncanSimon

By commenting out "source" and using "commandline" : "wsl -d Ubuntu-18.04" (from the docs here ) instead, it seems to work more or less the same way as it does on a fresh install that uses "source"

So what do you think is happening with "source": "Windows.Terminal.Wsl"?

DuncanSimon avatar Jul 16 '20 17:07 DuncanSimon

So, going out even further on a limb ... does it take a while for wsl to respond when you run wsl -l or start up Ubuntu?

DHowett avatar Jul 16 '20 18:07 DHowett

When it was in a broken state, I would say yes, at least compared to now (no errors because I'm using "commandLine" rather than "source".) When it was broken, it would take a little while to list Ubuntu, and then a bit longer to complete the command. Now it's instantaneous.

DuncanSimon avatar Jul 16 '20 18:07 DuncanSimon

Also, erm, now if I comment out the commandLine option and uncomment source, it works...

DuncanSimon avatar Jul 16 '20 18:07 DuncanSimon

It's like running it using commandLine has made it remember about WSL. Though I suspect this fix won't last?

DuncanSimon avatar Jul 16 '20 18:07 DuncanSimon

When it was broken, it would also take some time to launch and close down Terminal. Especially closing down - it would quit the UI but the application would stay 'active' in the taskbar for a little while.

DuncanSimon avatar Jul 16 '20 18:07 DuncanSimon

For a little bit of backstory... Terminal queries which WSL distributions exist every time it's launched, by running wsl -l. That might seem strange, but it's based on the official guidance from the WSL team. Now, sometimes wsl fails to return anything in time. That used to cause Terminal to hang indefinitely on startup!

I reached out to the dev lead who owns some of the WSL usermode experience, and he suggested that two seconds is "long enough" to give WSL to respond. Pursuant to that, we added a timeout: if WSL doesn't respond within 2 seconds, Terminal will move on as though WSL is wedged, stalled or stopped. Our launch issues went away overnight!

It seems like you're one of the suffering few that have lingering WSL issues. I might have to bounce you over to the WSL repository for this one, if only because they'll know best how to handle an issue like this. 😕

DHowett avatar Jul 16 '20 19:07 DHowett

If you'd like to make startup fully deterministic and move back to manual control for WSL, here's what you can do.

  1. Add "disabledProfileSources": [ "Windows.Terminal.Wsl" ] to the root node of your settings file
  2. Get rid of the source line from your WSL profile
  3. Add "commandline": "wsl -d Ubuntu-18.04"
  4. Add "icon": "ms-appx:///ProfileIcons/{9acb9455-ca41-5af7-950f-6bca1bc9722f}.png" to get the Tux icon back

DHowett avatar Jul 16 '20 19:07 DHowett

Note that doing this will disable all WSL distribution autodetection!

DHowett avatar Jul 16 '20 19:07 DHowett

Interesting! Well, for my circumstances the fact that I can use the "commandLine" option as a permanent fix is fine; I'm not worried about auto-detecting additional WSL distributions. I suppose any number of things could be causing WSL to be a bit slow? Whatever's happening is somewhat inconsistent as I've restarted my machine in the past few hours, which has always caused it to break in the past, and now it's fine. The only thing in the chain of events I've done differently is temporarily removing "source" and adding "commandLine": "wsl -d Ubuntu-18.04", which brought recognition of the default profile back, and then removing "commandLine" and putting "source" back in.

Regardless, I'm fine with the proposed solution and don't personally need further investigation (although I am personally curious!). Thanks for your help, that's some great detective work.

And of course getting Tux back is the most important thing ;)

DuncanSimon avatar Jul 16 '20 22:07 DuncanSimon

Much appreciated. Thanks for debugging with me! :smile:

DHowett avatar Jul 17 '20 01:07 DHowett