neovim / neovim

Vim-fork focused on extensibility and usability
https://neovim.io
Other
83.32k stars 5.7k forks source link

crash on chansend() write to redirected stdioopen() channel #30509

Closed titaniumtraveler closed 1 month ago

titaniumtraveler commented 1 month ago

Problem

Segmentation fault when redirecting stdout to a file in --headless-mode.

coredumpctl debug nvim returns the following backtrace (when using bt in the gdb session that is being opened):

#0  uv__check_before_write (nbufs=1, stream=0x0, send_handle=0x0) at nvim/.deps/build/src/libuv/src/unix/stream.c:1304
#1  uv_write2 (req=0x5630ac7fe240, stream=0x0, bufs=0x7ffdef52ee60, nbufs=1, send_handle=0x0, cb=0x563087d29867 <write_cb>)
    at nvim/.deps/build/src/libuv/src/unix/stream.c:1342
#2  0x0000563087d26823 in wstream_write (stream=0x5630ac8143e8, buffer=0x5630ac813b20) at nvim/src/nvim/event/wstream.c:91
#3  0x0000563087cb7a2f in channel_send (id=<optimized out>, data=<optimized out>, len=3, data_owned=<optimized out>, error=0x7ffdef52eef8)
    at nvim/src/nvim/channel.c:621
#4  0x0000563087d04ae0 in f_chansend (argvars=0x7ffdef52f1e0, rettv=0x7ffdef52f180, fptr=...) at nvim/src/nvim/eval/funcs.c:680
#5  0x0000563087cfd65b in call_internal_func (fname=<optimized out>, argcount=<optimized out>, argvars=0x7ffdef52f1e0, rettv=0x7ffdef52f180)
    at nvim/src/nvim/eval/funcs.c:285
#6  0x0000563087d22cdd in call_func (funcname=0x7da316380420 "chansend", len=8, rettv=0x7ffdef52f180, argcount_in=<optimized out>, argvars_in=<optimized out>, funcexe=0x7ffdef52f1a0)
    at nvim/src/nvim/eval/userfunc.c:1745
#7  0x0000563087da6bc3 in nlua_call (lstate=0x7da31689e380) at nvim/src/nvim/lua/executor.c:1208
#8  0x0000563087f6e826 in lj_BC_FUNCC ()
#9  0x0000563087f5a0dd in lua_pcall (L=L@entry=0x7da31689e380, nargs=nargs@entry=0, nresults=nresults@entry=0, errfunc=errfunc@entry=-2) at lj_api.c:1122
#10 0x0000563087d9a2f9 in nlua_pcall (lstate=0x7da31689e380, nargs=0, nresults=0) at nvim/src/nvim/lua/executor.c:174
#11 0x0000563087da7f02 in nlua_exec_file (path=<optimized out>) at nvim/src/nvim/lua/executor.c:1876
#12 0x0000563087e60deb in do_source (fname=0x7ffdef530227 "minimal.lua", check_other=<optimized out>, is_vimrc=<optimized out>, ret_sid=<optimized out>)
    at nvim/src/nvim/runtime.c:2224
#13 0x0000563087db33ea in source_startup_scripts (parmp=0x7ffdef52f650) at nvim/src/nvim/main.c:2095
#14 0x0000563087dad272 in main (argc=5, argv=<optimized out>) at nvim/src/nvim/main.c:463

Steps to reproduce

minimal.lua:

local channel = vim.fn.stdioopen { on_stdin = function() end }
vim.fn.chansend(channel, "123")

Running nvim:

nvim --headless --clean -u minimal.lua > stdout.txt

Expected behavior

I would expect nvim not to segfault because of that.

Nvim version (nvim -v)

v0.11.0-dev-828+g052875b9d

Vim (not Nvim) behaves the same?

Vim doesn't use libuv as far as I know

Operating system/version

Linux arch-book 6.10.7-arch1-1

Terminal name/version

alacritty 0.13.2 (bb8ea18e)/tmux 3.4

$TERM environment variable

tmux-256color

Installation

build from repo

titaniumtraveler commented 1 month ago

19374 might be caused from the same error