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

Inconsistent Segmentation Faults While lsp-zero is Enabled on MacOS #223

Open
michohl opened this issue May 2, 2023 · 4 comments
Open

Comments

@michohl
Copy link

michohl commented May 2, 2023

Summary of Issue

When I launch Neovim while I have lsp-zero configured I regularly get a segmentation fault on startup

$
zsh: segmentation fault  nvim
                             %

The above happens about 80% of the time when starting Neovim while lsp-zero is enabled. Commenting out the lsp.setup() call in my plugin configuration removes the problem. This only occurs on my MacOS setup and not my Linux setup though.

When the above occurs it breaks stdout until the session is closed and restarted.

I've tried creating a core dump and inspecting with lldb but I was unable to find anything obvious on what went wrong in the stack trace so I would appreciate some help in trying to pinpoint exactly where the issue is occuring and if it's a larger bug or a misconfiguration of some kind.

I would appreciate any help or guidance.

System Details:

OS: MacOS Ventura 13.3.1
Shell: zsh
Neovim Version: 0.8.3 (compiled locally)
Terminal Emulator: iTerm2

Neovim Version

NVIM v0.8.3
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by michohl@localhost

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/share/nvim"

Run :checkhealth for more info

lsp-zero configuration

local lsp = require('lsp-zero').preset({})

lsp.on_attach(function(client, bufnr)
  lsp.default_keymaps({buffer = bufnr})
end)

lsp.ensure_installed({
  -- Replace these with whatever servers you want to install
  'ansiblels',
  'awk_ls',
  'bashls',
  'clangd',
  'neocmake',
  'dockerls',
  'eslint',
  'gopls',
  'lua_ls',
  'pyright',
  'rust_analyzer',
  'terraformls',
  'tsserver',
  'yamlls'
})

lsp.setup()
@mar-muel
Copy link

mar-muel commented Jul 7, 2023

I'm using the same Mac version and experiencing similar issues (things used to work on my old Intel Mac). I'm not seeing any seg faults though, just no LSP support whatsover most of the time (it sometimes randomly works again?). Also no error logs in mason (or in lsp.log). Restarting the lsp client doesn't help.

nvim version:

NVIM v0.9.1
Build type: Release
LuaJIT 2.1.0-beta3

checkhealth while the issue occurs:

mason: require("mason.health").check()

mason.nvim ~
- OK mason.nvim version v1.6.0
- OK PATH: prepend
- OK Providers: 
  mason.providers.registry-api
  mason.providers.client
- OK neovim version >= 0.7.0

mason.nvim [Registries] ~
- OK Registry `github.com/mason-org/mason-registry version: 2023-07-06-wee-exit` is installed.

mason.nvim [Core utils] ~
- OK unzip: `UnZip 6.00 of 20 April 2009, by Info-ZIP.  Maintained by C. Spieler.  Send`
- OK wget: `GNU Wget 1.21.4 built on darwin22.4.0.`
- OK curl: `curl 7.88.1 (x86_64-apple-darwin22.0) libcurl/7.88.1 (SecureTransport) LibreSSL/3.3.6 zlib/1.2.11 nghttp2/1.51.0`
- OK gzip: `Apple gzip 403.100.6`
- OK tar: `bsdtar 3.5.3 - libarchive 3.5.3 zlib/1.2.11 liblzma/5.0.5 bz2lib/1.0.8 `
- OK bash: `GNU bash, version 3.2.57(1)-release (arm64-apple-darwin22)`
- OK sh: `Ok`

mason.nvim [Languages] ~
- WARNING Go: not available
  - ADVICE:
    - spawn: go failed with exit code - and signal -. go is not executable
- WARNING Composer: not available
  - ADVICE:
    - spawn: composer failed with exit code - and signal -. composer is not executable
- WARNING PHP: not available
  - ADVICE:
    - spawn: php failed with exit code - and signal -. php is not executable
- WARNING cargo: not available
  - ADVICE:
    - spawn: cargo failed with exit code - and signal -. cargo is not executable
- WARNING luarocks: not available
  - ADVICE:
    - spawn: luarocks failed with exit code - and signal -. luarocks is not executable
- OK Ruby: `ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin22]`
- WARNING javac: not available
  - ADVICE:
    - spawn: javac failed with exit code 1 and signal 0. The operation couldn’t be completed. Unable to locate a Java Runtime.
      Please visit http://www.java.com for information on installing Java.
      
- WARNING julia: not available
  - ADVICE:
    - spawn: julia failed with exit code - and signal -. julia is not executable
- WARNING java: not available
  - ADVICE:
    - spawn: java failed with exit code 1 and signal 0. The operation couldn’t be completed. Unable to locate a Java Runtime.
      Please visit http://www.java.com for information on installing Java.
      
- OK python: `Python 3.8.16`
- OK python3_host_prog: `Python 3.9.6`
- OK node: `v18.16.1`
- OK RubyGem: `3.0.3.1`
- OK python3_host_prog pip: `pip 21.2.4 from /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/site-packages/pip (python 3.9)`
- OK pip: `pip 23.1.2 from /Users/martin/miniconda3/envs/gal-api/lib/python3.8/site-packages/pip (python 3.8)`
- OK python venv: `Ok`
- OK npm: `9.5.1`

vim.lsp: require("vim.lsp.health").check()

- LSP log level : WARN
- Log path: /Users/martin/.local/state/nvim/lsp.log
- Log size: 0 KB

vim.lsp: Active Clients ~
- pyright (id=1, root_dir=/Users/martin/projects/testproject)

provider: health#provider#check

Clipboard (optional) ~
- OK Clipboard tool found: pbcopy

Python 3 provider (optional) ~
- Using: g:python3_host_prog = "/usr/bin/python3"
- Executable: /usr/bin/python3
- Python version: 3.9.6
- pynvim version: 0.4.3
- OK Latest pynvim is installed.

Python virtualenv ~
- OK no $VIRTUAL_ENV

Ruby provider (optional) ~
- Ruby: ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin22]
- WARNING `neovim-ruby-host` not found.
  - ADVICE:
    - Run `gem install neovim` to ensure the neovim RubyGem is installed.
    - Run `gem environment` to ensure the gem bin directory is in $PATH.
    - If you are using rvm/rbenv/chruby, try "rehashing".
    - See :help |g:ruby_host_prog| for non-standard gem installations.
    - You may disable this provider (and warning) by adding `let g:loaded_ruby_provider = 0` to your init.vim

Node.js provider (optional) ~
- Node.js: v18.16.1
- WARNING Missing "neovim" npm (or yarn, pnpm) package.
  - ADVICE:
    - Run in shell: npm install -g neovim
    - Run in shell (if you use yarn): yarn global add neovim
    - Run in shell (if you use pnpm): pnpm install -g neovim
    - You may disable this provider (and warning) by adding `let g:loaded_node_provider = 0` to your init.vim

Perl provider (optional) ~
- WARNING "Neovim::Ext" cpan module is not installed
  - ADVICE:
    - See :help |provider-perl| for more information.
    - You may disable this provider (and warning) by adding `let g:loaded_perl_provider = 0` to your init.vim

Will investigate further by installing older versions of lsp-zero...

@mar-muel
Copy link

mar-muel commented Jul 8, 2023

I've further investigated this using a blank init.lua with nothing except for the code in the lsp-zero tutorial. I've also checked :LspLog, but there are no errors in there.

It seems the issue occurs only on very long Python scripts (>500 lines), and only when commenting in specific lines. I start to think this issue is on the pyright language server side. 🤔

@VonHeikemen Any tips how we could further debug this? Like e.g. how could I see the pyright logs? Sorry, I'm not very familiar with how things work internally.

@VonHeikemen
Copy link
Owner

You can increase the level in the logs, add this in your config

vim.lsp.set_log_level("debug")

Then check the lsp logs again, using :LspLogs.

In neovim's wiki there is a section about debugging neovim itself. For more details you could join the neovim matrix channel, a lot of the developer core team are active there.

@mar-muel
Copy link

mar-muel commented Jul 8, 2023

Thanks! I can see the following logs when opening a file:

[DEBUG][2023-07-08 15:28:49] .../vim/lsp/rpc.lua:387    "rpc.receive"   {  id = 0,  jsonrpc = "2.0",  method = "workspace/configuration",  params = {    items = { {        scopeUri = "file:///Users/martin/projects/<path to project>",        section = "python"      } }  }}
[DEBUG][2023-07-08 15:28:49] .../vim/lsp/rpc.lua:387    "rpc.receive"   {  id = 1,  jsonrpc = "2.0",  method = "workspace/configuration",  params = {    items = { {        scopeUri = "file:///Users/martin/projects/<path to project>",        section = "python"      } }  }}
[DEBUG][2023-07-08 15:28:49] .../vim/lsp/rpc.lua:403    "server_request: callback result"       {  result = { {      analysis = {        autoSearchPaths = true,        diagnosticMode = "workspace",        useLibraryCodeForTypes = true      }    } },  status = true}
[DEBUG][2023-07-08 15:28:49] .../vim/lsp/rpc.lua:284    "rpc.send"      {  id = 0,  jsonrpc = "2.0",  result = { {      analysis = {        autoSearchPaths = true,        diagnosticMode = "workspace",        useLibraryCodeForTypes = true      }    } }}
[DEBUG][2023-07-08 15:28:49] .../vim/lsp/rpc.lua:403    "server_request: callback result"       {  result = { {      analysis = {        autoSearchPaths = true,        diagnosticMode = "workspace",        useLibraryCodeForTypes = true      }    } },  status = true}
[DEBUG][2023-07-08 15:28:49] .../vim/lsp/rpc.lua:284    "rpc.send"      {  id = 1,  jsonrpc = "2.0",  result = { {      analysis = {        autoSearchPaths = true,        diagnosticMode = "workspace",        useLibraryCodeForTypes = true      }    } }}
[DEBUG][2023-07-08 15:28:49] .../vim/lsp/rpc.lua:387    "rpc.receive"   {  id = 2,  jsonrpc = "2.0",  method = "workspace/configuration",  params = {    items = { {        scopeUri = "file:///Users/martin/projects/<path to project>",        section = "python.analysis"      } }  }}
[DEBUG][2023-07-08 15:28:49] .../vim/lsp/rpc.lua:403    "server_request: callback result"       {  result = { {      autoSearchPaths = true,      diagnosticMode = "workspace",      useLibraryCodeForTypes = true    } },  status = true}
[DEBUG][2023-07-08 15:28:49] .../vim/lsp/rpc.lua:284    "rpc.send"      {  id = 2,  jsonrpc = "2.0",  result = { {      autoSearchPaths = true,      diagnosticMode = "workspace",      useLibraryCodeForTypes = true    } }}
[DEBUG][2023-07-08 15:28:49] .../vim/lsp/rpc.lua:387    "rpc.receive"   {  id = 3,  jsonrpc = "2.0",  method = "workspace/configuration",  params = {    items = { {        scopeUri = "file:///Users/martin/projects/<path to project>",        section = "python.analysis"      } }  }}
[DEBUG][2023-07-08 15:28:49] .../vim/lsp/rpc.lua:403    "server_request: callback result"       {  result = { {      autoSearchPaths = true,      diagnosticMode = "workspace",      useLibraryCodeForTypes = true    } },  status = true}
[DEBUG][2023-07-08 15:28:49] .../vim/lsp/rpc.lua:284    "rpc.send"      {  id = 3,  jsonrpc = "2.0",  result = { {      autoSearchPaths = true,      diagnosticMode = "workspace",      useLibraryCodeForTypes = true    } }}
[DEBUG][2023-07-08 15:28:49] .../vim/lsp/rpc.lua:387    "rpc.receive"   {  id = 4,  jsonrpc = "2.0",  method = "workspace/configuration",  params = {    items = { {        scopeUri = "file:///Users/martin/projects/<path to project>",        section = "pyright"      } }  }}
[DEBUG][2023-07-08 15:28:49] .../vim/lsp/rpc.lua:403    "server_request: callback result"       {  result = { vim.NIL },  status = true}
[DEBUG][2023-07-08 15:28:49] .../vim/lsp/rpc.lua:284    "rpc.send"      {  id = 4,  jsonrpc = "2.0",  result = { vim.NIL }}
[DEBUG][2023-07-08 15:28:49] .../vim/lsp/rpc.lua:387    "rpc.receive"   {  id = 5,  jsonrpc = "2.0",  method = "workspace/configuration",  params = {    items = { {        scopeUri = "file:///Users/martin/projects/<path to project>",        section = "pyright"      } }  }}
[DEBUG][2023-07-08 15:28:49] .../vim/lsp/rpc.lua:403    "server_request: callback result"       {  result = { vim.NIL },  status = true}
[DEBUG][2023-07-08 15:28:49] .../vim/lsp/rpc.lua:284    "rpc.send"      {  id = 5,  jsonrpc = "2.0",  result = { vim.NIL }}
[DEBUG][2023-07-08 15:28:50] .../vim/lsp/rpc.lua:387    "rpc.receive"   {  jsonrpc = "2.0",  method = "window/logMessage",  params = {    message = "Found 30 source files",    type = 3  }}
[INFO][2023-07-08 15:28:50] ...lsp/handlers.lua:539     "Found 30 source files"
[DEBUG][2023-07-08 15:28:50] .../vim/lsp/rpc.lua:387    "rpc.receive"   {  jsonrpc = "2.0",  method = "window/logMessage",  params = {    message = "Found 30 source files",    type = 3  }}
[INFO][2023-07-08 15:28:50] ...lsp/handlers.lua:539     "Found 30 source files"

After that the language server just stops responding, and I can't interact with it anymore. E.g. gd would output the following logs:

[DEBUG][2023-07-08 15:32:19] .../lua/vim/lsp.lua:1392   "LSP[pyright]"  "client.request"        1       "textDocument/definition"       {  position = {    character = 63,    line = 360  },  textDocument = {    uri = "file:///Users/martin/projects/<path to file>.py"  }}       <function 1>    1
[DEBUG][2023-07-08 15:32:19] .../vim/lsp/rpc.lua:284    "rpc.send"      {  id = 3,  jsonrpc = "2.0",  method = "textDocument/definition",  params = {    position = {      character = 63,      line = 360    },    textDocument = {      uri = "file:///Users/martin/projects/<path to file>.py"    }  }}

But there seems to be no response after that 🤔

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

3 participants