elixir-lsp/elixir-ls

LS crashes when running the vscode extension

palash25 opened this issue · 26 comments

Environment

  • Elixir & Erlang versions (elixir --version): 1.10.2 & 22
  • Operating system: Ubuntu 18.04
  • Editor or IDE name (e.g. Emacs/VSCode): VSCode
  • LSP Client name: vscode-elixir-ls
  • If using VSCode, are you using "ElixirLS Fork: Elixir support and debugger" (note that it has "Fork" in the name)? I found this issue with both the ElixirLS extensions, and frankly I am not sure which one has the latest code and which of those two I should be using

Troubleshooting

  • Restart your editor (which will restart ElixirLS) sometimes fixes issues
  • Stop your editor, remove the entire .elixir_ls directory, then restart your editor (couldn't find this directory)

Crash report template

Delete this section if not reporting a crash

  1. If using a client other than VS Code, please try VSCode's "ElixirLS Fork: Elixir support and debugger" extension. Does it reproduce your failure? Yes both the vscode extensions give me the same error and I disable one of them while running the other

  2. Create a new Mix project with mix new empty, then open that project with VS Code and open an Elixir file. Is your issue reproducible on the empty project? If not, please publish a repo on Github that does reproduce it.

It gave the same error

  1. Check the output log by opening View > Output and selecting "ElixirLS" in the dropdown. Please include any output that looks relevant. (If ElixirLS isn't in the dropdown, the server failed to launch.)
    Here is the output

  2. Check the developer console by opening Help > Toggle Developer Tools and include any errors that look relevant.

This is the popup that I get when I start vscode with elixir ls fork

The ElixirLS server crashed 5 times in the last 3 minutes. The server will not be restarted.

ElixirLS Fork: Elixir support and debugger (Extension) 

@palash25 Is there any output above what you posted? I would expect to see the startup messages before any crashes. The startup messages should look something like:

Started ElixirLS Fork v0.3.3
Elixir version: "1.10.2 (compiled with Erlang/OTP 22)"
Erlang version: "22"

@polmuz and @groma84 I see that you put a thumbs up on here as well, can you also provide the ElixirLS output that you get when the extension crashes?

@axelson I have provided a link to a gist that contains the full output

@palash25 do you also get an error from running the language server in a terminal for this project?

What do you get if you follow these rough steps?

git clone
asdf install   # if you use asdf
mix deps.get
mix elixir_ls.release
./release/language_server.sh

I hadn't run this project locally but when I tried to build and run it today I got a compilation error

== Compilation error in file lib/language_server/dialyzer/analyzer.ex ==
** (RuntimeError) error parsing file /usr/lib/erlang/lib/dialyzer-4.1.1/src/dialyzer.hrl, got: {:error, :enoent}
    (elixir 1.10.2) lib/record/extractor.ex:84: Record.Extractor.read_file/2
    (elixir 1.10.2) lib/record/extractor.ex:50: Record.Extractor.extract_record/2
    lib/language_server/dialyzer/analyzer.ex:42: (module)
    (stdlib 3.12.1) erl_eval.erl:680: :erl_eval.do_apply/6
    (elixir 1.10.2) lib/kernel/parallel_compiler.ex:304: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/7

I have the same environment as the OP. I think the problem started after a vscode update. It's not specific to a given project.

This is my output when I open a brand new elixir project: https://gist.github.com/polmuz/c373045403c36c53786ebf9efed0bf5d

I tried to download and compile the project and I got:

== Compilation error in file lib/language_server/dialyzer/analyzer.ex ==
** (RuntimeError) error parsing file /usr/lib/erlang/lib/dialyzer-4.1.1/src/dialyzer.hrl, got: {:error, :enoent}
    (elixir 1.10.2) lib/record/extractor.ex:84: Record.Extractor.read_file/2
    (elixir 1.10.2) lib/record/extractor.ex:50: Record.Extractor.extract_record/2
    lib/language_server/dialyzer/analyzer.ex:42: (module)
    (stdlib 3.12.1) erl_eval.erl:680: :erl_eval.do_apply/6

I had to apt install erlang-src to make it work.

When I run the compiled language server I get this until I press enter and it crashes:

~/dev/elixir-ls(master) » ./release/language_server.sh                                                    
Content-Length: 171

{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"\u001B[22m\n14:20:46.191 [info]  Application elixir_ls_utils exited: :stopped\n\u001B[0m","type":4}}

Content-Length: 111

{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"Started ElixirLS Fork v0.3.3","type":4}}

Content-Length: 240

{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"\u001B[22m\n14:20:46.193 [info]  Application erl2ex exited: :stopped\n\u001B[0m\u001B[22m\n14:20:46.193 [info]  Application forms exited: :stopped\n\u001B[0m","type":4}}

Content-Length: 139

{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"Elixir version: \"1.10.2 (compiled with Erlang/OTP 21)\"","type":4}}

Content-Length: 105

{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"Erlang version: \"22\"","type":4}}


Content-Length: 584

{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"** (MatchError) no match of right hand side value: %{}\n    (elixir_ls_utils 0.3.3) lib/packet_stream.ex:49: ElixirLS.Utils.PacketStream.read_body/2\n    (elixir_ls_utils 0.3.3) lib/packet_stream.ex:12: anonymous fn/2 in ElixirLS.Utils.PacketStream.stream/1\n    (elixir 1.10.2) lib/stream.ex:1421: Stream.do_resource/5\n    (elixir 1.10.2) lib/stream.ex:1609: Enumerable.Stream.do_each/4\n    (elixir 1.10.2) lib/stream.ex:649: Stream.run/1\n    (stdlib 3.12.1) erl_eval.erl:680: :erl_eval.do_apply/6","type":2}}

@polmuz @palash25 how have you installed elixir and erlang?

I was getting the same error/output (I mean: view>output>ElixirLS) as @palash25
I'm using Windows WSL(2) and ElixirLS as remote extension. It worked fine till las update of (VS)Code.
I'm connecting Code to an Ubuntu 18.08.
I installed Erlang & Elixir from the repo Erlang Solutions.
It's working fine now **after I installed erlang with "apt install esl-erlang".
I THINK what I did before was: adding the erlang solutions repo and installing elixir ("apt install elixir") instead of: "apt install esl-erlang" -> "apt install elixir" (as instructed in https://elixir-lang.org/install.html#unix-and-unix-like).

I don't know if that is of any help.

@asincrono by latest update of VSCode are you referring to 1.44.2? https://github.com/microsoft/vscode/releases

Or do you mean the latest release of vscode-elixir-ls? (Since the fork was very recently merged back). It seems very plausible that this issue is related to a non-full installation of Erlang. Probably the previous version of the extension did not rely on as many erlang features.

I can only easily test on Ubuntu 19.10, but I don't get the same error when I only install elixir and not esl-erlang. I don't get an error when running release/language_server.sh (until I get the expected error when I press enter), although I do get an error when I try to compile elixir-ls

@polmuz does installing esl-erlang instead of erlang-src also fix the issue for you?

@axelson it's working for me now, I saw an update screen today when I opened vscode and when I went to my test elixir project it asked me to compile something related to dialyzer and now everything works.

Regarding on how I installed elixir, originally I installed it adding the erlang solutions repo for ubuntu as instructed here https://elixir-lang.org/install.html#unix-and-unix-like, that worked fine until ~3 days ago when I started getting this error.

Yesterday I tried installing elixir with asdf, but I had the same problem. Same error message (and it was using asdf version (Elixir version: "1.10.2 (compiled with Erlang/OTP 22)" vs Elixir version: "1.10.2 (compiled with Erlang/OTP 21)" on my system).

I'm 90% sure the issue was related to a vscode update but I don't know how to test different vscode versions on my system easily. If you have an idea on how to do that I'm happy to help chasing the bug down. Otherwise, it seems to be gone now on my system.

Thanks for the help!

@polmuz @palash25 how have you installed elixir and erlang?

iirc I used this guide to install both https://elixir-lang.org/install.html#unix-and-unix-like

@axelson the version I have right now is 1.44.2. Everything is working fine. I think the stuff @polmuz saw was the (re)build of the PTL. I saw the same thing.

There was problably not a full instalation, as when I did de "apt install esl-erlang" there were packages that were not installed.

I'm sorry I can't be of more help.

All right, I also did sudo apt install esl-erlang and found a few packages were missing. After installing I ran vscode and didn't get the crash message and instead got a pop up saying "Building core Dialyzer Elixir PLT"

@axelson should we add this in the Readme? something like "in case of a crash message install any missing dependencies using apt install esl-erlang"

@palash25 Yes, I think that would be a great addition to the troubleshooting section of the readme

Hey everyone, I have been also facing the same issue and I have tried everything that was suggested above in this thread but i still haven't been able to resolve this issue
This is the complete error that I get:
https://gist.github.com/gupta82anish/a69e5d4d23caa516f4d700b9d99e0fe3
I have been really frustrated with this and I'll appreciate the help, thanks so much!

@gupta82anish What OS are you using ? I had the same problem on Fedora 32, and I just solved it by installing erlang package (esl-erlang if you're on Debian).

@gupta82anish what OS and version are you using and exactly how did you install elixir and erlang?

@axelson @thomasnaudin I am running Ubuntu 18.04 LTS, and I installed Erlang and Elixir by following this guide https://elixir-lang.org/install.html#unix-and-unix-like

@gupta82anish but apt install esl-erlang did not help? I'm surprised since that helped both palash25 and asincrono, who are both on 18.04 LTS

@axelson I know, but it didn't help. ElixirLS still keeps crashing. I have given the link to the gist log if it helps?

I tried running apt install esl-erlang again and now it's giving this error:

Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 erlang-syntax-tools : Depends: erlang-base (= 1:22.3.2-1) but it is not going to be installed or
                                erlang-base-hipe (= 1:22.3.2-1)
 esl-erlang : Conflicts: erlang-syntax-tools
E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.

Any idea about this?

@gupta82anish I'm not sure. Maybe you could do a sudo apt-get update first and try again. If it still doesn't work maybe ask at https://askubuntu.com/

Just wanted to share my recent experience with a persistent crash.

I was using the forked version of ElixirLS for ages and it worked great, then one day after an update it just crashed persistently. I gave up in the end and went back to the old version of the extension and it was working again at least so left it at that.

Recently it started crashing again, I realise now because the forked extension has updated the old extension so I'm getting the same problem as before.

After some digging, I discovered that the extension was using an old asdf elixir install that I don't use any more and overriding the version of elixir I was using in my path - after deleting my .asdf folder it's all working again now 🎉

Thanks for all your work on this. Hope this might help someone else.