code-server icon indicating copy to clipboard operation
code-server copied to clipboard

[Bug]: Cannot invoke `code-server` from integrated terminal

Open Emporea opened this issue 2 years ago • 21 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

OS/Web Information

  • Web Browser: Firefox 102
  • Local OS: Win10
  • Remote OS: Ubuntu
  • Remote Architecture: 86
  • code-server --version: 4.5.0 (4.4.0)

Steps to Reproduce

  1. docker run codeserver:latest
  2. try to install extensions via code-server code-server --install-extension ms-python
  3. asd

Expected

Installation of Extension

Actual

Console throws error /usr/lib/code-server/lib/vscode/bin/remote-cli/code-server: 12: /usr/lib/code-server/lib/vscode/node: not found

Logs

No response

Screenshot/Video

No response

Does this issue happen in VS Code or GitHub Codespaces?

  • [X] I cannot reproduce this in VS Code.
  • [X] I cannot reproduce this in GitHub Codespaces.

Are you accessing code-server over HTTPS?

  • [X] I am using HTTPS.

Notes

No response

Emporea avatar Jul 12 '22 19:07 Emporea

"Workaround" is a downgrade to 4.4.0 There it seems to work.

#5334 also has a bug appearently solved by downgrading.

Emporea avatar Jul 12 '22 21:07 Emporea

I have the same issue but need 4.5.0 as it's required to run Github Copilot. Any other ideas for a workaround?

dx034 avatar Jul 13 '22 08:07 dx034

I think what's going on is upstream vscode is injecting an update to the PATH environment variable to an undesirable location.

Here is my invocation that generates the error (note: specifically running /opt/code-server/bin/code-server (where I installed code-server in my container) bypasses the issue):

user 6619ab0c7518 ~
$ code-server --help
/opt/code-server/lib/vscode/bin/remote-cli/code-server: 12: /opt/code-server/lib/vscode/node: not found

And here is my $PATH:

user 6619ab0c7518 ~
$ env | grep PATH
PATH=/home/user/bin:/home/user/.local/bin:/opt/code-server/lib/vscode/bin/remote-cli:/home/user/.local/bin:/home/user/bin:/home/user/bin:/home/user/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/sonar-scanner/bin:/opt/sonar-scanner/bin

I certainly did not put /opt/code-server/lib/vscode/bin/remote-cli into my PATH myself.

jbalonso avatar Jul 14 '22 15:07 jbalonso

cc @code-asher any ideas on this one?

jsjoeio avatar Jul 18 '22 22:07 jsjoeio

I think what's going on is upstream vscode is injecting an update to the PATH environment variable to an undesirable location.

@jsjoeio I can confirm this.

JupyterLab Terminal:

$ echo $PATH
/opt/code-server/bin:/opt/julia/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

code-server Terminal:

$ echo $PATH
/opt/code-server/lib/vscode/bin/remote-cli:/opt/code-server/bin:/opt/julia/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

👉 Compare /opt/code-server/bin/code-server with /opt/code-server/lib/vscode/bin/remote-cli/code-server.

(/opt/code-server being the root directory of my code-server installation)

benz0li avatar Jul 20 '22 07:07 benz0li

This should have been fixed prior to the release of code-server v4.5.1.

I am sticking with v4.4.0 for now.

benz0li avatar Jul 20 '22 07:07 benz0li

The way code-server is released(/run?), it behaves like a remote installation. This ~might be~ is the reason, why /opt/code-server/lib/vscode/bin/remote-cli is prepended to PATH.

benz0li avatar Jul 20 '22 07:07 benz0li

@jsjoeio Please add this issue to the July 2022 milestone.

benz0li avatar Jul 20 '22 07:07 benz0li

The way code-server is released(/run?), it behaves like a remote installation. This might be the reason, why /opt/code-server/lib/vscode/bin/remote-cli is prepended to PATH.

Interesting 🤔 I'll chat with @code-asher and see how we can fix this. Thanks for bringing it up everyone!

jsjoeio avatar Jul 20 '22 16:07 jsjoeio

@code-asher Compare /opt/code-server/bin/code-server with /opt/code-server/lib/vscode/bin/remote-cli/code-server.

(/opt/code-server being the root directory of my code-server installation)

benz0li avatar Jul 20 '22 17:07 benz0li

So I might be wrong but the only location where upstream vs code prepends the PATH variable with the remote-cli folder is here:

https://github.com/microsoft/vscode/blob/619ab6d1ba7eef9ad418456a5fe5c7805f01a7ab/src/vs/server/node/extensionHostConnection.ts#L53-L59

This is also used to spawn the console (https://github.com/microsoft/vscode/blob/619ab6d1ba7eef9ad418456a5fe5c7805f01a7ab/src/vs/server/node/remoteTerminalChannel.ts#L191) so thats prop. the locaiton where the env variable and thus the PATH gets broken

fritterhoff avatar Jul 20 '22 18:07 fritterhoff

My pretty simple idea would be to check inside the code-server script it's location. So in case of being inside the remote-cli folder instead of the bin it maybe would be a solution to change the way the node location is detected.

fritterhoff avatar Jul 20 '22 18:07 fritterhoff

Uhh yeah /opt/code-server/lib/vscode/bin/remote-cli/code-server is a VS Code thing, not our script. Maybe we should remove it during the packaging step since I have no idea if it would even work if it could find Node (but maybe we look into whether we can make it work first). /opt/code-server/bin/code-server is the right one.

code-asher avatar Jul 20 '22 20:07 code-asher

Or maybe we patch to prevent it from getting added to the PATH? Or patch to add our own script to the path instead.

code-asher avatar Jul 20 '22 20:07 code-asher

Maybe we should remove it during the packaging step since I have no idea if it would even work if it could find Node (but maybe we look into whether we can make it work first).

Applying

diff --git a/opt/code-server/lib/vscode/bin/remote-cli/code-server b/opt/code-server/lib/vscode/bin/remote-cli/code-server
index bd8c43b..94bbf1e 100755
--- a/opt/code-server/lib/vscode/bin/remote-cli/code-server
+++ b/opt/code-server/lib/vscode/bin/remote-cli/code-server
@@ -9,4 +9,4 @@ VERSION="1.68.1"
 COMMIT="30d9c6cd9483b2cc586687151bcbcd635f373630"
 EXEC_NAME="code-server"
 CLI_SCRIPT="$ROOT/out/server-cli.js"
-"$ROOT/node" "$CLI_SCRIPT" "$APP_NAME" "$VERSION" "$COMMIT" "$EXEC_NAME" "$@"
+"$ROOT/../node" "$CLI_SCRIPT" "$APP_NAME" "$VERSION" "$COMMIT" "$EXEC_NAME" "$@"

results in

$ code-server --version
1.68.1
30d9c6cd9483b2cc586687151bcbcd635f373630
x64

when executed in code-server Terminal. Compared to

$ code-server --version
4.5.1 97d170331b51ee75c8e4bbdab23c755e3eeaaa8c with Code 1.68.1

when executed in JupyterLab Terminal.


$ /opt/code-server/bin/code-server --help
code-server 4.5.1 97d170331b51ee75c8e4bbdab23c755e3eeaaa8c with Code 1.68.1

Usage: code-server [options] [path]
    - Opening a directory: code-server ./path/to/your/project
    - Opening a saved workspace: code-server ./path/to/your/project.code-workspace

Options
      --auth                   The type of authentication to use. [password, none]
      --password               The password for password authentication (can only be passed in via $PASSWORD or the config file).
      --hashed-password        The password hashed with argon2 for password authentication (can only be passed in via $HASHED_PASSWORD or the config file).
                               Takes precedence over 'password'.
      --cert                   Path to certificate. A self signed certificate is generated if none is provided.
      --cert-host              Hostname to use when generating a self signed certificate.
      --cert-key               Path to certificate key when using non-generated cert.
      --disable-telemetry      Disable telemetry.
      --disable-update-check   Disable update check. Without this flag, code-server checks every 6 hours against the latest github release and
                               then notifies you once every week that a new release is available.
      --disable-file-downloads Disable file downloads from Code. This can also be set with CS_DISABLE_FILE_DOWNLOADS set to 'true' or '1'.
   -h --help                   Show this output.
      --open                   Open in browser on startup. Does not work remotely.
      --bind-addr              Address to bind to in host:port. You can also use $PORT to override the port.
      --config                 Path to yaml config file. Every flag maps directly to a key in the config file.
      --socket                 Path to a socket (bind-addr will be ignored).
      --socket-mode            File mode of the socket.
   -v --version                Display version information.
      --user-data-dir          Path to the user data directory.
      --extensions-dir         Path to the extensions directory.
      --list-extensions        List installed VS Code extensions.
      --force                  Avoid prompts when installing VS Code extensions.
      --install-extension      Install or update a VS Code extension by id or vsix. The identifier of an extension is `${publisher}.${name}`.
                               To install a specific version provide `@${version}`. For example: '[email protected]'.
      --enable-proposed-api    Enable proposed API features for extensions. Can receive one or more extension IDs to enable individually.
      --uninstall-extension    Uninstall a VS Code extension by id.
      --show-versions          Show VS Code extension versions.
      --github-auth            GitHub authentication token (can only be passed in via $GITHUB_TOKEN or the config file).
      --proxy-domain           Domain used for proxying ports.
   -e --ignore-last-opened     Ignore the last opened directory or workspace in favor of an empty window.
   -n --new-window             Force to open a new window.
   -r --reuse-window           Force to open a file or folder in an already opened window.
 -vvv --verbose                Enable verbose logging.
      --link                   (deprecated) Securely bind code-server via our cloud service with the passed name. You'll get a URL like
                               https://hostname-username.coder.co at which you can easily access your code-server instance.
                               Authorization is done via GitHub.

vs

$ /opt/code-server/lib/vscode/bin/remote-cli/code-server --help
code-server 1.68.1

Usage: code-server [options][paths...]

To read from stdin, append '-' (e.g. 'ps aux | grep code | code-server -')

Options
  -d --diff <file> <file>           Compare two files with each other.
  -a --add <folder>                 Add folder(s) to the last active window.
  -g --goto <file:line[:character]> Open a file at the path on the specified line and character position.
  -n --new-window                   Force to open a new window.
  -r --reuse-window                 Force to open a file or folder in an already opened window.
  -w --wait                         Wait for the files to be closed before returning.
  -h --help                         Print usage.

Extensions Management
  --list-extensions                   List the installed extensions.
  --show-versions                     Show versions of installed extensions, when using --list-extensions.
  --category <category>               Filters installed extensions by provided category, when using --list-extensions.
  --install-extension <ext-id | path> Installs or updates an extension. The argument is either an extension id or a path to a
                                      VSIX. The identifier of an extension is '${publisher}.${name}'. Use '--force' argument to
                                      update to latest version. To install a specific version provide '@${version}'. For
                                      example: '[email protected]'.
  --uninstall-extension <ext-id>      Uninstalls an extension.

Troubleshooting
  -v --version Print version.
  --verbose    Print verbose output (implies --wait).
  -s --status  Print process usage and diagnostics information.

benz0li avatar Jul 21 '22 04:07 benz0li

If

/opt/code-server/bin/code-server is the right one.

you should

patch to prevent it [/opt/code-server/lib/vscode/bin/remote-cli] from getting added to the PATH?

benz0li avatar Jul 21 '22 04:07 benz0li

I'm currently trying what happens if I simply remove the code-server script located in remote-cli folder.

fritterhoff avatar Jul 21 '22 04:07 fritterhoff

grafik So removing the code-server script inside the remote-cli folder at least works in my case fine... Not sure if there are some negative side-effects I did not see in my first tests?

fritterhoff avatar Jul 21 '22 04:07 fritterhoff

@code-asher In code-server v4.4.0/v4.3.0 there is /opt/code-server/lib/vscode/bin/remote-cli/code-oss.
👉 /opt/code-server/lib/vscode/bin/remote-cli is prepended to PATH, too; but there is code-oss instead of code-server at the said path.


My workaround is renaming /opt/code-server/lib/vscode/bin/remote-cli/code-server to /opt/code-server/lib/vscode/bin/remote-cli/code-oss and replacing all occurrences of code-server with code-oss in

  1. /opt/code-server/lib/vscode/bin/remote-cli/code-oss
  2. /opt/code-server/lib/vscode/bin/helpers/browser.sh

code-server v4.4.0:

$ tree /opt/code-server/lib/vscode/bin
/opt/code-server/lib/vscode/bin
├── code-server-oss
├── helpers
│   └── browser.sh
└── remote-cli
    └── code-oss

2 directories, 3 files

$ cat /opt/code-server/lib/vscode/bin/code-server-oss 
#!/usr/bin/env sh
#
# Copyright (c) Microsoft Corporation. All rights reserved.
#

case "$1" in
        --inspect*) INSPECT="$1"; shift;;
esac

ROOT="$(dirname "$(dirname "$(readlink -f "$0")")")"

"$ROOT/node" ${INSPECT:-} "$ROOT/out/server-main.js" "$@"

$ cat /opt/code-server/lib/vscode/bin/helpers/browser.sh 
#!/usr/bin/env sh
#
# Copyright (c) Microsoft Corporation. All rights reserved.
#
ROOT=$(dirname "$(dirname "$(dirname "$0")")")

APP_NAME="code-oss"
VERSION="1.66.2"
COMMIT=","
EXEC_NAME="code-oss"
CLI_SCRIPT="$ROOT/out/server-cli.js"
"$ROOT/node" "$CLI_SCRIPT" "$APP_NAME" "$VERSION" "$COMMIT" "$EXEC_NAME" "--openExternal" "$@"

$ cat /opt/code-server/lib/vscode/bin/remote-cli/code-oss 
#!/usr/bin/env sh
#
# Copyright (c) Microsoft Corporation. All rights reserved.
#
ROOT=$(dirname "$(dirname "$(dirname "$0")")")

APP_NAME="code-oss"
VERSION="1.66.2"
COMMIT=","
EXEC_NAME="code-oss"
CLI_SCRIPT="$ROOT/out/server-cli.js"
"$ROOT/node" "$CLI_SCRIPT" "$APP_NAME" "$VERSION" "$COMMIT" "$EXEC_NAME" "$@"

benz0li avatar Jul 21 '22 06:07 benz0li

In code-server v4.1.0 /opt/code-server/vendor/modules/code-oss-dev/bin is prepended to PATH; the said path only containing helpers/{browser.cmd,browser.sh}.

benz0li avatar Jul 21 '22 17:07 benz0li

Will be resolved by #5360

tjcran avatar Jul 25 '22 16:07 tjcran