-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
neovim hang at 100% CPU when interrupted with <C-c> #20726
Comments
vim-airline/vim-airline#2588 I can reproduce this freezing behavior with here is a reproduction repo: https://github.com/vhoyer-bug-reproductions/airline-freeze-on-C-c |
also this is happening with |
btw, vim-airline doesn't use lua, so I don't know if the labels are correctly applied, or maybe it's a different problem with the same behavior, should I open a new issue? |
Not sure if this is the same bug or not, but it sounds similar, and I believe I found fairly minimal steps to reproduce:
local vim = assert(vim)
local loop = vim.loop
local i = 0
local function do_cmd()
i = i + 1
print ("spawn: " .. i)
loop.spawn('echo', {
args = {'hi'}
}, function () end)
end
local function start_polling()
vim.defer_fn(function ()
local j = 0
while j < 100 do
do_cmd()
j = j + 1
end
start_polling()
end, 100)
end
start_polling()
After several seconds the terminal should hang and Neovim will lock up at 100% CPU. Obviously this example is pretty contrived, but the freeze happens often enough on my dev workflow to be annoying. (I have a plugin that periodically polls information by launching a bunch of commands). It appears to be a race conditions where if Ctrl-C is pressed at the exact wrong time during the job life cycle, it get's stuck in a loop. Poking around in GDB indicates that Neovim thinks it's getting a constant stream of Ctrl-C's, so it appears that maybe To further add to the mystery, I replicated this on 3 different machines (All Linux-based, Arch and Debian), however, I could not get the bug to replicate on a Gentoo server I run. All versions of Neovim were built from source though, so it seems strange to have different behavior. Maybe the server hardware is beefy enough that it masks the issue. I was also able to replicate this issue on the packaged release of Neovim in Arch linux:
|
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
We have clear repro steps given above. So I've hidden redundant comments (though the hints are appreciated). |
This comment was marked as off-topic.
This comment was marked as off-topic.
i was able to not trigger this bug every day by adding this in my alacritty config:
it basically disables C-c in every tui and maps C-A-c to C-c instead. |
I've had the issue of
While debugging this I noticed the following the logs
I had the following settings.
So I added this autocmd as a workaround.
This smells like a race condition that is exacerbated by the foldmethod, but I haven't been able to reproduce since modifying the foldexpr. |
I'll also point out that I saw the same thing as @jrahm listed above. I spent a while stepping through with GDB before I stumbled upon the workaround in my previous comment. |
@mattpallissard That's a great finding! I can also confirm that setting In your workaround you globally autocmd TermOpen * setlocal foldmethod=manual I've made a more refined and clean version of the repro with minimal dependencies based on @mattpallissard's observation: -- Run with: nvim --clean -u repro.lua, and hit <Ctrl-C>
vim.o.foldmethod = 'expr'
vim.o.foldexpr = 'MyFold()'
vim.cmd [[
function! MyFold() abort
" Do some expensive(?) computation inside foldexpr, to increase the chance of neovim freezing
" Note: this function gets called **VERY OFTEN**, every single time terminal draws with a new character
let i = 0 | while i <= 20 | let i += 1 | endwhile
return 0
endfunction
]]
vim.cmd [[ term base64 < /dev/urandom ]]
-- vim.cmd [[ setlocal foldmethod=manual ]] -- a workaround to prevent hanging (#20726)
vim.cmd [[ startinsert ]] Some additional notes regarding the above reproThe following (lua function instead of vimscript foldexpr function) doesn't result in hanging. So it's probably related to vimscript execution?
The infinite loop happens hereWith this repro and a bit of playing around with gdb, I also found that the infinite loop happens around:
|
I don't know the codebase well, but it seems like there are likely two problems
|
Neovim often freezes when hitting `<Ctrl-C>` on a terminal. As a workaround for this bug, we disable folding (evaluation of `&foldexpr`) on terminal buffers because we don't really need folding in a terminal. See neovim/neovim#20726
Related?
|
I'm not sure if it's related or not, but I also have a After executing Tested with minimal.lua below, with -- minimal.lua
for name, url in pairs({
-- ADD PLUGINS _NECESSARY_ TO REPRODUCE THE ISSUE, e.g:
-- some_plugin = 'https://github.com/author/plugin.nvim'
['nvim-treesitter'] = 'https://github.com/nvim-treesitter/nvim-treesitter',
}) do
local install_path = vim.fn.fnamemodify('nvim_issue/' .. name, ':p')
if vim.fn.isdirectory(install_path) == 0 then
vim.fn.system({ 'git', 'clone', '--depth=1', url, install_path, })
end
vim.opt.runtimepath:append(install_path)
end
vim.opt.foldmethod = 'expr'
vim.opt.foldexpr = 'nvim_treesitter#foldexpr()' |
There's an open issue where there appears to be race conditions when hitting Ctrl-C during lua deferred functions. Lots of people were hitting this when using treesitter folding in terminals. I was using indent, which may or may not have a similar problem, but either way I'm happy to disable folding in terminal. References: - issue: neovim/neovim#20726 - workaround: neovim/neovim#20726 (comment)
May or may not be related, while attempting to debug this issue I've been using
Is it possible that somehow the combination of receing the @justinmk, is it possible this issue is not related to lua code interruption or folds? |
Neovim version (nvim -v)
NVIM v0.8.0
Vim (not Nvim) behaves the same?
not using vim
Operating system/version
Void Linux kernel 5.10.147
Terminal name/version
alacritty 0.10.1
$TERM environment variable
screen-256color
Installation
Void Linux xbps package manager
How to reproduce the issue
I am able to consistently get neovim to hang at 100% CPU when using fzf-lua, opening any interface and quickly pressing
<C-c>
.What happens behind the scenes is fzf-lua opening a new window and running
termopen
with the fzf command and then waits for the job'son_exit
callback.While stuck I ran
strace -s 99 -ffp <pid>
on the neovim pid and it seems to be polling a no longer existing thread (not sure about that, but in the below pid27433
no longer exists), the loop below continues endlessly:In an effort to understand where this issue comes from I added trace logging to my plugin from the moment the
termopen
succeeds untilon_exit
is called, you can enable logging to file (only with thetrace
branch) with:With the above setup the file gets overwritten each time the fzf-lua interface is open, the results indicate neovim is stuck in an endless loop calling the
vim._on_key(char)
function within the runtimeruntime/lua/vim/_editor.lua:560
, relevant part of the log right before it gets stuck:I think this might be related to neovim not yet interrupting lua code as explained in #6800?
@famiu, @ZyX-I, @justinmk, if my analysis is correct, do you have any idea why this happens? What part of the code causes this? Any workarounds I can apply before #19096 is merged (aside from remapping
<C-c>
)?Expected behavior
Neovim should be able to handle
<C-c>
.Actual behavior
Neovim will occasionally become unresponsive when pressing
<C-c>
.The text was updated successfully, but these errors were encountered: