folke / lazy.nvim

💤 A modern plugin manager for Neovim
https://lazy.folke.io/
Apache License 2.0
15.14k stars 366 forks source link

bug: task `git.status` does a sync call in it's `on_exit` #1569

Closed CWood-sdf closed 5 months ago

CWood-sdf commented 5 months ago

Did you check docs and existing issues?

Neovim version (nvim -v)

nightly, pulled 1 hr ago

Operating system/version

arch

Describe the bug

In commit 0614ca6ca629704cb1846c0d6f9a250b526900b9, a bug exists somewhere that causes an infinite loop in something. I don't have many details on it because I am about to fall asleep and it is very late, I am posting the issue now just to get it on your radar so you could do some preliminary checks for something.

Steps To Reproduce

I'll do this tomorrow

Expected Behavior

not to have an infinite loop

Repro

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here
max397574 commented 5 months ago

is it reproducible with the minimal template you sent?

Idea: rockspec has a dependency which has the plugin itself as dependency again

folke commented 5 months ago

@max397574 that shouldn't cause issue

folke commented 5 months ago

I fixed some things related to running tasks, that may have fixed the issue you experienced. When you have the time, can you:

folke commented 5 months ago

Just tried your neovim config. Is the error below what you're referring to?

image

folke commented 5 months ago

I'm debugging your profile. Will add some remarks.

folke commented 5 months ago

looking into: image

folke commented 5 months ago

Found the issue (not lazy.nvim's fault):

It's never a good idea to import modules top-level in specs. Always use closures...

CWood-sdf commented 5 months ago

I was able to replicate the bug with a repro.lua:

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
    "folke/tokyonight.nvim",
    "stevearc/conform.nvim",
    --"nvim-treesitter/nvim-treesitter",
    --{ "nvim-neotest/neotest-plenary" },
    {
        "nvim-neotest/neotest",
        opts = {
            adapters = {
                ["neotest-plenary"] = {
                    min_init = "./tests/init.lua",
                },
            }
        },
    },

    "nvim-neotest/nvim-nio",
    -- add any other plugins here
}
require("lazy").setup(plugins, {
    root = root .. "/plugins",
    change_detection = {
        notify = false,
    },
    -- install = {
    --  -- missing = false,
    -- },
    checker = {
        enabled = true,
        frequency = 300,
        notify = false,
    },

})

vim.cmd.colorscheme("tokyonight")

vim.defer_fn(function()
    require("lazy.manage.checker").check()
    if require("lazy.status").has_updates() then
    print(require('lazy.status').updates())
    end
    require("lazy.manage.checker").check()
    if require("lazy.status").has_updates() then
    print(require('lazy.status').updates())
    end
    require("lazy.manage.checker").check()
    if require("lazy.status").has_updates() then
    print(require('lazy.status').updates())
    end

end, 100)

I think it is the same problem as #1568, the git-remote-https program gets hung, but it seems that somewhere along the .check() function stack, there is a synchronous function that forces the function to wait for the git-remote-https process to end (which takes a while). This problem also occurs with the opts.checker auto checker for status lines (which causes neovim to randomly freeze up for about two minutes every five minutes (because my checker frequency is 300s).

folke commented 5 months ago

What is this repro supposed to show? It doesn't do anything special for me...

CWood-sdf commented 5 months ago

For me the git-remote-https process hangs about 80% of the time that neovim is opened with the repro. Somewhere in the .check() is synchronous (at least that's the best explanation I have), so it causes neovim to completely freeze up, using 100% of a single core for the 2 minutes that git-remote-https is sitting.

folke commented 5 months ago

The only part that could cause this is if you have a plugin dir with a git dirty doc/tags file. I just pushed a temp fix for that. Will make a proper fix tomorrow. Can you confirm that with the latest lazy.nvim HEAD you no longer see the hanging? Something weird with cursor flickering might still happen for now.

CWood-sdf commented 5 months ago

unfortunately that did not fix the problem. there's still 100% usage on one cpu core

folke commented 5 months ago

Did you open the repro and ran :Lazy update inside to update lazy? I didn't make a new release yet, so if you didn't update or if you'd just delete the .repro directory, it would have used the old version

folke commented 5 months ago

Closing, since with the latest changes I just released it should no longer happen, even on slower machines. Do let me know if the issue would not be resolved