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

elixir-ls for vscode keeps crashing when using fish as the default shell #374

Closed
phamdangtrung opened this issue Sep 20, 2023 · 7 comments
Closed

Comments

@phamdangtrung
Copy link

For some reasons, elixir-ls for vscode used to work with fish shell under POSIX but as of right now, it keeps crashing whenever I launch my project. If I switch my default shell to bash, elixir-ls successfully initializes with its server.

I'm using WSL2 Ubuntu with fish shell as the default shell.

Environment

  • Elixir & Erlang versions (elixir --version): Erlang/OTP 26 [erts-14.0.2] [source] [64-bit] [smp:6:6] [ds:6:6:10] [async-threads:1] [jit:ns]

Elixir 1.15.5 (compiled with Erlang/OTP 26)

  • VSCode ElixirLS version: 0.16.0
  • Operating System Version: linux 5.15.90.1-microsoft-standard-WSL2

Crash report template

Running /home/phamd/.vscode-server/extensions/jakebecker.elixir-ls-0.16.0/elixir-ls-release/launch.sh
Preffered shell fish is not supported, continuing in POSIX shell
Looking for ASDF install
ASDF install found in /home/phamd/.asdf/asdf.sh, sourcing
Installing ElixirLS release v0.16.0
Running in /home/phamd/projects/temp/empty
Install complete
/home/phamd/.vscode-server/extensions/jakebecker.elixir-ls-0.16.0/elixir-ls-release/launch.sh: 102: Syntax error: redirection unexpected
[Error - 9:04:15 AM] Server initialization failed.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Info  - 9:04:15 AM] Connection to server got closed. Server will restart.
true
[Error - 9:04:15 AM] ElixirLS - empty client: couldn't create connection to server.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
Running /home/phamd/.vscode-server/extensions/jakebecker.elixir-ls-0.16.0/elixir-ls-release/launch.sh
Preffered shell fish is not supported, continuing in POSIX shell
Looking for ASDF install
ASDF install found in /home/phamd/.asdf/asdf.sh, sourcing
Installing ElixirLS release v0.16.0
Running in /home/phamd/projects/temp/empty
Install complete
/home/phamd/.vscode-server/extensions/jakebecker.elixir-ls-0.16.0/elixir-ls-release/launch.sh: 102: Syntax error: redirection unexpected
[Error - 9:04:17 AM] Server initialization failed.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Info  - 9:04:17 AM] Connection to server got closed. Server will restart.
true
[Error - 9:04:17 AM] ElixirLS - empty client: couldn't create connection to server.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
Running /home/phamd/.vscode-server/extensions/jakebecker.elixir-ls-0.16.0/elixir-ls-release/launch.sh
Preffered shell fish is not supported, continuing in POSIX shell
Looking for ASDF install
ASDF install found in /home/phamd/.asdf/asdf.sh, sourcing
Installing ElixirLS release v0.16.0
Running in /home/phamd/projects/temp/empty
Install complete
/home/phamd/.vscode-server/extensions/jakebecker.elixir-ls-0.16.0/elixir-ls-release/launch.sh: 102: Syntax error: redirection unexpected
[Error - 9:04:18 AM] Server initialization failed.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Info  - 9:04:18 AM] Connection to server got closed. Server will restart.
true
[Error - 9:04:18 AM] ElixirLS - empty client: couldn't create connection to server.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Error - 9:04:18 AM] Restarting server failed
  Message: Pending response rejected since connection got disposed
  Code: -32097 
Running /home/phamd/.vscode-server/extensions/jakebecker.elixir-ls-0.16.0/elixir-ls-release/launch.sh
Preffered shell fish is not supported, continuing in POSIX shell
Looking for ASDF install
ASDF install found in /home/phamd/.asdf/asdf.sh, sourcing
Installing ElixirLS release v0.16.0
Running in /home/phamd/projects/temp/empty
Install complete
/home/phamd/.vscode-server/extensions/jakebecker.elixir-ls-0.16.0/elixir-ls-release/launch.sh: 102: Syntax error: redirection unexpected
[Error - 9:04:20 AM] Server initialization failed.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Info  - 9:04:20 AM] Connection to server got closed. Server will restart.
true
[Error - 9:04:20 AM] ElixirLS - empty client: couldn't create connection to server.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Error - 9:04:20 AM] Restarting server failed
  Message: Pending response rejected since connection got disposed
  Code: -32097 
Running /home/phamd/.vscode-server/extensions/jakebecker.elixir-ls-0.16.0/elixir-ls-release/launch.sh
Preffered shell fish is not supported, continuing in POSIX shell
Looking for ASDF install
ASDF install found in /home/phamd/.asdf/asdf.sh, sourcing
Installing ElixirLS release v0.16.0
Running in /home/phamd/projects/temp/empty
Install complete
/home/phamd/.vscode-server/extensions/jakebecker.elixir-ls-0.16.0/elixir-ls-release/launch.sh: 102: Syntax error: redirection unexpected
[Error - 9:04:21 AM] Server initialization failed.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Error - 9:04:21 AM] The ElixirLS - empty server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.
[Error - 9:04:21 AM] ElixirLS - empty client: couldn't create connection to server.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Error - 9:04:21 AM] Restarting server failed
  Message: Pending response rejected since connection got disposed
  Code: -32097 
@tobbbles
Copy link

Started to get the same, but a different crash error:

Running /home/tobbbles/.vscode/extensions/jakebecker.elixir-ls-0.16.0/elixir-ls-release/launch.sh
Preffered shell fish is not supported, continuing in POSIX shell
Looking for ASDF install
ASDF not found
Looking for rtx executable
rtx executable found in /usr/local/bin/rtx, activating
/home/tobbbles/.vscode/extensions/jakebecker.elixir-ls-0.16.0/elixir-ls-release/launch.sh: line 50: set: -g: invalid option
set: usage: set [-abefhkmnptuvxBCEHPT] [-o option-name] [--] [-] [arg ...]
[Error - 14:06:00] Server initialization failed.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Error - 14:06:00] The ElixirLS - mito server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.
[Error - 14:06:00] ElixirLS - mito client: couldn't create connection to server.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Error - 14:06:00] Restarting server failed
  Message: Pending response rejected since connection got disposed
  Code: -32097 

@thiagomajesk
Copy link

I noticed this some time ago and have the same problem on WSL2 using fish. It used to work fine though

@JavierL1
Copy link

JavierL1 commented Sep 25, 2023

I'm getting the equivalent error for ash shell on an alpine elixir container.
I decided to use version 0.15.0 of the extension in the meantime.

@emk
Copy link

emk commented Sep 26, 2023

Hello, and thank you to everyone for helping figure this out! I can confirm this happens on Ubuntu 20.04.6 LTS with fish set as my interactive shell.

The first bit of related code appears here:

#!/bin/sh
# Actual launcher. This does the hard work of figuring out the best way
# to launch the language server or the debugger.

# Running this script is a one-time action per project launch, so we opt for
# code simplicity instead of performance. Hence some potentially redundant
# moves here.

# First order of business, see whether we can setup asdf-vm

did_relaunch=$1

# Get the user's preferred shell
preferred_shell=$(basename "$SHELL")

case "${did_relaunch}" in
  "")
    if [ "$preferred_shell" = "bash" ]; then
      >&2 echo "Preffered shell is bash, relaunching"
      exec "$(which bash)" "$0" relaunch
    elif [ "$preferred_shell" = "zsh" ]; then
      >&2 echo "Preffered shell is zsh, relaunching"
      exec "$(which zsh)" "$0" relaunch
    else
      >&2 echo "Preffered shell $preferred_shell is not supported, continuing in POSIX shell"
    fi
    ;;
  *)
    # We have an arg2, so we got relaunched
    ;;
esac

This script begins with #!/bin/sh, which points to dash on Ubuntu. This is a bare-bones POSIX shell, and it will fail if you accidentally use any bash specific syntax. The second problem occurs here:

    else
      >&2 echo "Preffered shell $preferred_shell is not supported, continuing in POSIX shell"
    fi

At this point, if we've configured any interactive SHELL except bash or zsh, then this code falls through and continues using /bin/sh, which is really /bin/dash on Ubuntu. (Or ash on Alpine, as @JavierL1 points out.)

This works fine until we reach line 102:

  97   │ if [ "$preferred_shell" = "bash" ]; then
  98   │   # we need to make sure ELS_ELIXIR_OPTS gets splitted by word
  99   │   # parse it as bash array
 100   │   # shellcheck disable=SC3045
 101   │   # shellcheck disable=SC3011
 102   │   IFS=' ' read -ra elixir_opts <<< "$ELS_ELIXIR_OPTS"
 103   │   # shellcheck disable=SC3054
 104   │   # shellcheck disable=SC2068

Here, we encounter <<<, which is a non-standard Bash feature that doesn't work in Posix shells.

But we shouldn't get here! This code is protected by if [ "$preferred_shell" = "bash" ]; then. Do not ask me how this script can first print Preffered shell $preferred_shell is not supported, continuing in POSIX shell, and then run the bash branch at line 97. I don't have asdf or .config/elixir_ls/setup.sh, either of which might inject variable values if present. So I'm not sure what's happening to $preferred_shell. Something fairly horrible might be happening?

Anyway, to kludge around this issue, you can install bash and edit the first line to read !/bin/bash. This will get the script to run far enough to work with VS Code.

But I'm awfully curious about what's actually happening here.

@kek
Copy link

kek commented Oct 9, 2023

@emk's workaround works for me... Should perhaps the first line of launch.sh be changed to contain /bin/bash instead of /bin/sh? (I guess elixir-ls would then depend on bash, but maybe it already does?)

@lukaszsamson
Copy link
Collaborator

The upcoming release 0.17 will resolve the issue. Fish support has been added and the bash and zsh specific scripts have been extracted to separate files

@lukaszsamson
Copy link
Collaborator

Version 0.17 with support for fish and improvements for other shells has been released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants