rancher-sandbox / rancher-desktop

Container Management and Kubernetes on the Desktop
https://rancherdesktop.io
Apache License 2.0
5.98k stars 283 forks source link

Rancher Desktop fails to interact with WSL2 if GitBash legacy console support is enabled #5399

Open pshutt97 opened 1 year ago

pshutt97 commented 1 year ago

Actual Behavior

When legacy console support is enabled within GitBash on a Windows PC, Rancher desktop fails to launch as it cannot interact with WSL2.

Steps to Reproduce

Download and install GitBash. Enable legacy console support. Factory reset Rancher Desktop and try to launch. Both rancher-desktop and rancher-desktop-data WSL2 distributions must be unregistered.

Result

Rancher Desktop fails to register or unregister WSL distributions rancher-desktop and rancher-desktop-data. Therefore, an error message is displayed stating that there is an "Error starting Kubernetes". image

background.log shows the error message for this issue.

Expected Behavior

It is expected that, no matter what shells and emulated shells are present on the machine, Rancher Desktop should still be able to launch and register its required distributions in WSL2

Additional Information

No response

Rancher Desktop Version

1.9.1

Rancher Desktop K8s Version

N/A

Which container engine are you using?

moby (docker cli)

What operating system are you using?

Windows

Operating System / Build Version

Windows 11

What CPU architecture are you using?

x64

Linux only: what package format did you use to install Rancher Desktop?

None

Windows User Only

Cisco AnyConnect, Zscaler, Microsoft Defender and Symantec Endpoint Protection

gunamata commented 1 year ago

@pshutt97 , I am trying to reproduce this. By enable legacy console support, do you mean performing below steps?

gunamata commented 1 year ago

I could reproduce the issue with below steps.

The application doesn't launch and in my case I did not see any error pop up either. I see below error message in the background.log

2023-08-25T22:51:01.891Z: Stopping background process Win32 socket proxy (pid <none>).
2023-08-25T22:51:02.131Z: Error starting up: c [Error]: C:\Windows\system32\wsl.exe exited with code 4294967295
    at ChildProcess.<anonymous> (C:\Program Files\Rancher Desktop\resources\app.asar\dist\app\background.js:1:9473)
    at ChildProcess.emit (node:events:527:28)
    at ChildProcess._handle.onexit (node:internal/child_process:291:12) {
  command: [
    'C:\\Windows\\system32\\wsl.exe',
    '--distribution',
    'openSUSE-Tumbleweed',
    '--exec',
    '/bin/wslpath',
    '-a',
    '-u',
    'C:\\Program Files\\Rancher Desktop\\resources\\resources\\linux\\bin\\docker-buildx'
  ],
  stdout: 'U\x00n\x00s\x00u\x00p\x00p\x00o\x00r\x00t\x00e\x00d\x00 \x00c\x00o\x00n\x00s\x00o\x00l\x00e\x00 \x00s\x00e\x00t\x00t\x00i\x00n\x00g\x00s\x00.\x00 \x00I\x00n\x00 \x00o\x00r\x00d\x00e\x00r\x00 \x00t\x00o\x00 \x00u\x00s\x00e\x00 \x00t\x00h\x00i\x00s\x00 \x00f\x00e\x00a\x00t\x00u\x00r\x00e\x00,\x00 \x00t\x00h\x00e\x00 \x00l\x00e\x00g\x00a\x00c\x00y\x00 \x00c\x00o\x00n\x00s\x00o\x00l\x00e\x00 \x00m\x00u\x00s\x00t\x00 \x00b\x00e\x00 \x00d\x00i\x00s\x00a\x00b\x00l\x00e\x00d\x00.\x00\r\x00\r\x00\n' +
    '\x00',
  code: 4294967295,
  [Symbol(child-process.command)]: 'C:\\Windows\\system32\\wsl.exe --distribution openSUSE-Tumbleweed --exec /bin/wslpath -a -u C:\\Program Files\\Rancher Desktop\\resources\\resources\\linux\\bin\\docker-buildx'
}

When I try to run the command that failed in the terminal, I get below error message.

>C:\\Windows\\system32\\wsl.exe --distribution openSUSE-Tumbleweed --exec /bin/wslpath -a -u C:\\Program Files\\Rancher Desktop\\resources
\resources\\linux\\bin\\docker-buildx
Unsupported console settings. In order to use this feature, the legacy console must be disabled.

This looks like the behavior from WSL as per this issue but I am not sure if something changed since that issue was raised couple of years back and if there's any workaround to it.

jandubois commented 1 year ago

Expected Behavior

It is expected that, no matter what shells and emulated shells are present on the machine, Rancher Desktop should still be able to launch and register its required distributions in WSL2

It seems like wsl.exe is in general incompatible with the legacy console option. I'm not sure why the cmd.exe console is involved when Rancher Desktop runs wsl.exe as a subprocess; we need to investigate if there is a way to avoid that, or if this is an OS level thing.

Random idea: Maybe we can use CreatePseudoConsole and use it to execute subprocesses (see also Windows Command-Line: Introducing the Windows Pseudo Console (ConPTY)).

But it is possible that the best we can do is to detect this situation and throw up an error dialog instead of exiting silently.

The best workaround right now is to disable the legacy console settings.