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

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

Closed
4 tasks done
Emporea opened this issue Jul 12, 2022 · 21 comments · Fixed by #5360
Closed
4 tasks done

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

Emporea opened this issue Jul 12, 2022 · 21 comments · Fixed by #5360
Assignees
Labels
bug Something isn't working high-priority This issue needs to be resolved ASAP
Milestone

Comments

@Emporea
Copy link

Emporea commented Jul 12, 2022

Is there an existing issue for this?

  • 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?

  • I cannot reproduce this in VS Code.
  • I cannot reproduce this in GitHub Codespaces.

Are you accessing code-server over HTTPS?

  • I am using HTTPS.

Notes

No response

@Emporea Emporea added bug Something isn't working triage This issue needs to be triaged by a maintainer labels Jul 12, 2022
@Emporea
Copy link
Author

Emporea commented Jul 12, 2022

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

#5334 also has a bug appearently solved by downgrading.

@dx034
Copy link

dx034 commented Jul 13, 2022

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

@jbalonso
Copy link

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.

@jsjoeio
Copy link
Contributor

jsjoeio commented Jul 18, 2022

cc @code-asher any ideas on this one?

@benz0li
Copy link
Contributor

benz0li commented Jul 20, 2022

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
Copy link
Contributor

benz0li commented Jul 20, 2022

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
Copy link
Contributor

benz0li commented Jul 20, 2022

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
Copy link
Contributor

benz0li commented Jul 20, 2022

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

@jsjoeio jsjoeio added high-priority This issue needs to be resolved ASAP and removed triage This issue needs to be triaged by a maintainer labels Jul 20, 2022
@jsjoeio jsjoeio added this to the July 2022 milestone Jul 20, 2022
@jsjoeio
Copy link
Contributor

jsjoeio commented Jul 20, 2022

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!

@benz0li
Copy link
Contributor

benz0li commented Jul 20, 2022

@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 benz0li mentioned this issue Jul 20, 2022
4 tasks
@fritterhoff
Copy link
Contributor

fritterhoff commented Jul 20, 2022

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
Copy link
Contributor

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.

@code-asher
Copy link
Member

code-asher commented Jul 20, 2022

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
Copy link
Member

code-asher commented Jul 20, 2022

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 code-asher changed the title [Bug]: /usr/lib/code-server/lib/vscode/node: not found [Bug]: Cannot invoke code-server from integrated terminal Jul 20, 2022
@benz0li
Copy link
Contributor

benz0li commented Jul 21, 2022

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
Copy link
Contributor

benz0li commented Jul 21, 2022

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?

@fritterhoff
Copy link
Contributor

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

@fritterhoff
Copy link
Contributor

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?

@benz0li
Copy link
Contributor

benz0li commented Jul 21, 2022

@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
Copy link
Contributor

benz0li commented Jul 21, 2022

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}.

@tjcran
Copy link

tjcran commented Jul 25, 2022

Will be resolved by #5360

benz0li added a commit to b-data/jupyterlab-r-docker-stack that referenced this issue Sep 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working high-priority This issue needs to be resolved ASAP
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants