NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.44k stars 13.65k forks source link

Neovim master crashes when spawning a process from libuv #132433

Closed gpanders closed 3 years ago

gpanders commented 3 years ago

Describe the bug

Spawning a process via libuv from within Neovim master built with Nix results in a SIGABRT.

I know this sounds oddly specific, but many Neovim plugins written in Lua spawn external commands using libuv, this ends up crashing Neovim quite regularly.

Steps To Reproduce

Steps to reproduce the behavior:

  1. Run neovim master

    nix run github:neovim/neovim?dir=contrib -- -u NONE

  2. Spawn a new process:

    :lua vim.loop.spawn("ls", {}, function() end)

  3. Neovim crashes with SIGABRT

Expected behavior

No SIGABRT.

Additional context

This error does not occur when I build Neovim using packages from my non-Nix package manager. In this case, LuaJIT and libuv are bundled with Neovim. My suspicion is that this isn't a bug with Neovim but rather with LuaJIT or libuv, or if not a bug in any one of those in particular then in the way they're being packaged together to build Neovim.

Note that I can reproduce the same thing on stable Nix 2.3, so this is not a result of using nixUnstable.

Here is the stack trace from lldb:

(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
  * frame #0: 0x00007fff6a78233a libsystem_kernel.dylib`__pthread_kill + 10
    frame #1: 0x00007fff6a83ee60 libsystem_pthread.dylib`pthread_kill + 430
    frame #2: 0x00007fff6a709808 libsystem_c.dylib`abort + 120
    frame #3: 0x00000001016c2d96 libuv.1.dylib`uv__signal_start + 1494
    frame #4: 0x00000001016c11c1 libuv.1.dylib`uv_spawn + 593
    frame #5: 0x00000001009e6f27 libluv.1.30.0.dylib`luv_spawn + 2263
    frame #6: 0x0000000100a997f5 libluajit-5.1.2.dylib`___lldb_unnamed_symbol95$$libluajit-5.1.2.dylib + 68
    frame #7: 0x0000000100aae6e2 libluajit-5.1.2.dylib`lua_pcall + 162
    frame #8: 0x00000001001ae1eb nvim`nlua_typval_exec(lcmd="vim.loop.spawn(\"ls\", {}, function() end)", lcmd_len=40, name=":lua", args=0x0000000000000000, argcount=0, special=false, ret_tv=0x0000000000000000) at executor.c:1133:7
    frame #9: 0x00000001001aedbf nvim`ex_lua(eap=0x00007ffeefbfe2d0) at executor.c:1308:3
    frame #10: 0x000000010012dc2a nvim`do_one_cmd(cmdlinep=0x00007ffeefbfe6a8, flags=0, cstack=0x00007ffeefbfe6b0, fgetline=(nvim`getexline at ex_getln.c:2505), cookie=0x0000000000000000) at ex_docmd.c:1964:5
    frame #11: 0x000000010012a8f6 nvim`do_cmdline(cmdline=0x0000000000000000, fgetline=(nvim`getexline at ex_getln.c:2505), cookie=0x0000000000000000, flags=0) at ex_docmd.c:595:20
    frame #12: 0x0000000100213d2a nvim`nv_colon(cap=0x00007ffeefbfecf8) at normal.c:4687:18
    frame #13: 0x00000001002117dc nvim`normal_execute(state=0x00007ffeefbfec68, key=58) at normal.c:1146:3
    frame #14: 0x0000000100314f0c nvim`state_enter(s=0x00007ffeefbfec68) at state.c:69:26
    frame #15: 0x0000000100208947 nvim`normal_enter(cmdwin=false, noexmode=false) at normal.c:462:3
    frame #16: 0x00000001001b6e3b nvim`main(argc=3, argv=0x00007ffeefbfefd8) at main.c:562:3
    frame #17: 0x00007fff6a63acc9 libdyld.dylib`start + 1
    frame #18: 0x00007fff6a63acc9 libdyld.dylib`start + 1
(lldb)

Notify maintainers

@manveru @rvolosatovs @Ma27

Metadata

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-darwin"`
 - host os: `Darwin 19.6.0, macOS 10.15.7`
 - multi-user?: `no`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.4pre20210707_02dd6bb`
 - channels(greande): `"nixpkgs-21.11pre305747.ab5b6828af2"`
 - nixpkgs: `/Users/greande/.nix-defexpr/channels/nixpkgs`

Maintainer information:

# a list of nixpkgs attributes affected by the problem
attribute:
  - neovim
  - lua
  - libuv
# a list of nixos modules affected by the problem
module:
gpanders commented 3 years ago

I wonder if this is related https://github.com/libuv/libuv/commit/04289fa326b790c1a4abb236d1f9d913bacfc8c6

gpanders commented 3 years ago

Nothing to see here folks... An objdump -p revealed that I apparently had another version of libuv installed on my system and Neovim was being linked against that instead of the Nix version. Hopefully I didn't waste anyone else's time but my own :)

rvolosatovs commented 3 years ago

Hmm, I wonder it's actually a packaging issue. In https://github.com/NixOS/nixpkgs/pull/110837/commits/58ba227160122cea95df57ce71edd44e44e4e233 I added "-DUSE_BUNDLED=OFF" to be consistent with the upstream flake at that time (https://github.com/neovim/neovim/blob/2bcf18deaa32ad371b6de349b353d42e9b1c9ea0/contrib/flake.nix#L25). The flake has been since updated and this line was removed upstream in https://github.com/neovim/neovim/commit/de909bf48b5b845602204d84597af38a93a6ebd1 I will open a PR for removing this option - judging by the discussion in https://github.com/neovim/neovim/issues/15054 it seems that it would fix the issue. We have no reason to use system libraries anyway as far as I understand.

teto commented 3 years ago

the line was removed precisely because you added it in nixpkgs: it didn't need to be there anymore ^^ Note that the flake is kinda best effort, I change it when I detect an issue.

EDIT: it's possible the libuv in the flake doesn't match the one recommended in neovim's build system. I run master and haven't noticed that kind of crash yet

rvolosatovs commented 3 years ago

Alright, can you confirm that this is not an issue caused by packaging then?

teto commented 3 years ago

I've just edited my previous message to make it clearer that there may be a mismatch between the flake dependencies and the one recommended in neovim's build system. For instance the bundled ones uses libuv 1.34 https://github.com/neovim/neovim/blob/master/third-party/CMakeLists.txt#L152 but the flake uses 1.42. I run master and haven't noticed that kind of crash but if the issue is confirmed we could update the flake.

rvolosatovs commented 3 years ago

Thanks for the explanation! Closing this again.