Vscode-remote-release: Remote WSL not working with custom kernel built from source provided by kernel.org

Created on 4 Jun 2020  路  8Comments  路  Source: microsoft/vscode-remote-release

Remote WSL is not working with Linux kernel 5.7 compiled from the source downloaded from kernel.org. Previous issue #2809 is different from my issue because the author had built the source downloaded from WSL's GitHub repo.
To build the kernel, however, I an using the configuration provided by the WSL' repo.

When I run the command `code .' in Ubuntu-wsl VS-Code shows the following errors.

Could not fetch remote environment
Failed to connect to the remote extension host server (Error: connect ECONNREFUSED 127.0.0.1:43587)

I also edited my code.sh as told in issue #2809, but the errors still persist.

  • VSCode Version: 1.45
  • Local OS Version: win 10 2004
  • Remote OS Version: Ubuntu 20.04 on WSL2
  • Remote Extension/Connection Type: SSH/Docker/WSL

Steps to Reproduce:

  1. Build the kernel 5.7 source from kernel.org and edit the .wslconfig file to use the new kernel.
  2. Edit code.sh to support the new kernel then try to run vs code.

Here's what my remote-WSL log look like.

[2020-06-04 05:41:06.339] Resolving wsl+Ubuntu, resolveAttempt: 1
[2020-06-04 05:41:06.431] Starting VS Code Server inside WSL (Ubuntu)
[2020-06-04 05:41:06.431] Extension version: 0.44.2, Windows build: 19041. Multi distro support: available. WSL path support: enabled
[2020-06-04 05:41:06.679] Probing if server is already installed: C:\WINDOWS\System32\wsl.exe -d Ubuntu -e sh -c "[ -d ~/.vscode-server/bin/5763d909d5f12fe19f215cbfdd29a91c0fa9208a ] && printf found || ([ -f /etc/alpine-release ] && printf alpine-; uname -m)"
[2020-06-04 05:41:06.891] Probing result: found
[2020-06-04 05:41:06.891] Server install found in WSL
[2020-06-04 05:41:06.892] Launching C:\WINDOWS\System32\wsl.exe -d Ubuntu sh -c '"$VSCODE_WSL_EXT_LOCATION/scripts/wslServer.sh" 5763d909d5f12fe19f215cbfdd29a91c0fa9208a stable .vscode-server 0  ' in c:\Users\Nisarg\.vscode\extensions\ms-vscode-remote.remote-wsl-0.44.2}
[2020-06-04 05:41:07.291] Setting up server environment: Looking for /home/nisarg/.vscode-server/server-env-setup. Not found.
[2020-06-04 05:41:07.291] WSL version: 5.7.0-microsoft-standard Ubuntu
[2020-06-04 05:41:07.291] WSL2-shell-PID: 16694
[2020-06-04 05:41:07.291] Starting server: /home/nisarg/.vscode-server/bin/5763d909d5f12fe19f215cbfdd29a91c0fa9208a/server.sh  --port=0 --use-host-proxy --enable-remote-auto-shutdown 
[2020-06-04 05:41:07.893] 
[2020-06-04 05:41:07.893] 
[2020-06-04 05:41:07.893] *
[2020-06-04 05:41:07.893] * Visual Studio Code Server
[2020-06-04 05:41:07.893] *
[2020-06-04 05:41:07.893] * Reminder: You may only use this software with Visual Studio family products,
[2020-06-04 05:41:07.893] * as described in the license https://aka.ms/vscode-remote/license
[2020-06-04 05:41:07.893] *
[2020-06-04 05:41:07.893] 
[2020-06-04 05:41:07.893] 
[2020-06-04 05:41:08.499] IP Address: 172.15.73.153
[2020-06-04 05:41:08.499] Extension host agent listening on 43587
[2020-06-04 05:41:08.499] 
[2020-06-04 05:41:08.499] 
[2020-06-04 05:41:08.499] [11:11:08] Extension host agent started.
[2020-06-04 05:41:08.500] WSL resolver response: 127.0.0.1:43587
[2020-06-04 05:41:08.500] To debug connection issues, open a local browser on http://127.0.0.1:43587/version

code.sh file:

#!/usr/bin/env sh
#
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
COMMIT="5763d909d5f12fe19f215cbfdd29a91c0fa9208a"
APP_NAME="code"
QUALITY="stable"
NAME="Code"
DATAFOLDER=".vscode"
VSCODE_PATH="$(dirname "$(dirname "$(realpath "$0")")")"
ELECTRON="$VSCODE_PATH/$NAME.exe"
if grep -qi Microsoft /proc/version; then
    # in a wsl shell
    WSL_BUILD=$(uname -r | sed -E 's/^[0-9.]+-([0-9]+)-Microsoft|([0-9]+).([0-9]+).([0-9]+)-microsoft-standard|.*/\1\2\3\4/')
    if [ -z "$WSL_BUILD" ]; then
        WSL_BUILD=0
    fi

    # code block for new kernel/
    if [ $WSL_BUILD -ge 500 -a $WSL_BUILD -lt 700 ]; then
        export WSLENV=ELECTRON_RUN_AS_NODE/w:$WSLENV
        CLI=$(wslpath -m "$VSCODE_PATH/resources/app/out/cli.js")

        # use the Remote WSL extension if installed
        WSL_EXT_ID="ms-vscode-remote.remote-wsl"
        ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" --locate-extension $WSL_EXT_ID >/tmp/remote-wsl-loc.txt 2>/dev/null
        WSL_EXT_WLOC=$(cat /tmp/remote-wsl-loc.txt)
        if [ -n "$WSL_EXT_WLOC" ]; then
            # replace \r\n with \n in WSL_EXT_WLOC
            WSL_CODE=$(wslpath -u "${WSL_EXT_WLOC%%[[:cntrl:]]}")/scripts/wslCode.sh
            "$WSL_CODE" "$COMMIT" "$QUALITY" "$ELECTRON" "$APP_NAME" "$DATAFOLDER" "$@"
            exit $?
        fi
    # end new block
    #this elif is new, make it if
    elif [ $WSL_BUILD -ge 17063 ]; then
        # $WSL_DISTRO_NAME is available since WSL builds 18362, also for WSL2
        # WSLPATH is available since WSL build 17046
        # WSLENV is available since WSL build 17063
        export WSLENV=ELECTRON_RUN_AS_NODE/w:$WSLENV
        CLI=$(wslpath -m "$VSCODE_PATH/resources/app/out/cli.js")

        # use the Remote WSL extension if installed
        WSL_EXT_ID="ms-vscode-remote.remote-wsl"

        if [ $WSL_BUILD -ge 41955 -a $WSL_BUILD -lt 41959 ]; then
            # WSL2 workaround for https://github.com/microsoft/WSL/issues/4337
            CWD="$(pwd)"
            cd "$VSCODE_PATH"
            cmd.exe /C ".\\bin\\$APP_NAME.cmd --locate-extension $WSL_EXT_ID >%TEMP%\\remote-wsl-loc.txt"
            WSL_EXT_WLOC=$(cmd.exe /C type %TEMP%\\remote-wsl-loc.txt)
            cd "$CWD"
        else
            ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" --locate-extension $WSL_EXT_ID >/tmp/remote-wsl-loc.txt 2>/dev/null
            WSL_EXT_WLOC=$(cat /tmp/remote-wsl-loc.txt)
        fi
        if [ -n "$WSL_EXT_WLOC" ]; then
            # replace \r\n with \n in WSL_EXT_WLOC
            WSL_CODE=$(wslpath -u "${WSL_EXT_WLOC%%[[:cntrl:]]}")/scripts/wslCode.sh
            "$WSL_CODE" "$COMMIT" "$QUALITY" "$ELECTRON" "$APP_NAME" "$DATAFOLDER" "$@"
            exit $?
        fi
    else
        # If running under older WSL, don't pass cli.js to Electron as
        # environment vars cannot be transferred from WSL to Windows
        # See: https://github.com/Microsoft/BashOnWindows/issues/1363
        #      https://github.com/Microsoft/BashOnWindows/issues/1494
        "$ELECTRON" "$@"
        exit $?
    fi
elif [ -x "$(command -v cygpath)" ]; then
    CLI=$(cygpath -m "$VSCODE_PATH/resources/app/out/cli.js")
else
    CLI="$VSCODE_PATH/resources/app/out/cli.js"
fi
ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" "$@"
exit $?

needs-more-info wsl

Most helpful comment

That was probably a hvsocket connection problem. It looks like the official 5.7.x linux kernel is not ready yet for WSL2.

You can find a working 5.7 kernel in https://github.com/nathanchance/WSL2-Linux-Kernel
It's even ready for VScode Remote so you don't need to update any file to make it work.

Here it is if you want to test it.
bzImage.txt

All 8 comments

Can you please upload the 5.7.0 kernel? (just rename it to vmlinux.txt and drop it in the message box here)

vmlinux.txt
here.

That was probably a hvsocket connection problem. It looks like the official 5.7.x linux kernel is not ready yet for WSL2.

You can find a working 5.7 kernel in https://github.com/nathanchance/WSL2-Linux-Kernel
It's even ready for VScode Remote so you don't need to update any file to make it work.

Here it is if you want to test it.
bzImage.txt

its 4.19, You were right though. The problem seems to be with kernel 5.7 itself.

It's 5.7 kernel but uname was hacked to show as 4.19. dmesg | head shows the real kernel version.

For now the best is waiting for Microsoft to update their kernel repo for kernel 5.7.

Ok, I didn't know that. I would still like to keep the issue open so that Microsoft can fix it.

Looking at the logs, the problem is that we try to connect to the server through 127.0.0.1, which we should only do for WSL1.
There has been a fix a while back to improve the detection of WSL1 vs WSL2 in 0.44.4.

Is this still not working for you?

It is working now. Thanks.

Was this page helpful?
0 / 5 - 0 ratings