nvim-tree / nvim-tree.lua

A file explorer tree for neovim written in lua

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nvim freezes by inifinite loop of nvim-tree when working on C:\Users\{username}\AppData\Local

regomne opened this issue · comments

Description

When nvim tree tries to dir_up to C:\Users\{username}\AppData\Local by mapped key in Windows, nvim freezes and cpu usage 100% and memory usage continues increasing.

Neovim version

NVIM v0.8.2
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3

Operating system and version

Windows 10

nvim-tree version

215b29b

Minimal config

vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=d:/temp/nvt-min/site]]
local package_root = "d:/temp/nvt-min/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"
local function load_plugins()
  require("packer").startup {
    {
      "wbthomason/packer.nvim",
      "nvim-tree/nvim-tree.lua",
      "nvim-tree/nvim-web-devicons",
      -- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
    },
    config = {
      package_root = package_root,
      compile_path = install_path .. "/plugin/packer_compiled.lua",
      display = { non_interactive = true },
    },
  }
end
if vim.fn.isdirectory(install_path) == 0 then
  print "Installing nvim-tree and dependencies."
  vim.fn.system { "git", "clone", "--depth=1", "https://github.com/wbthomason/packer.nvim", install_path }
end
load_plugins()
require("packer").sync()
vim.cmd [[autocmd User PackerComplete ++once echo "Ready!" | lua setup()]]
vim.opt.termguicolors = true
vim.opt.cursorline = true

-- MODIFY NVIM-TREE SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
_G.setup = function()
  require("nvim-tree").setup {
	  view = { mappings = { list = { key = {'-'}, action = 'dir_up' } } }
  }
end

Steps to reproduce

  1. run Windows Terminal, and cd to C:\Users\{username}\AppData\Local\Temp
  2. nvim -nu d:\temp\nvt-min.lua
  3. :NvimTreeToggle
  4. press J (ensure the cursor not on the directory line)
  5. press -

Expected behavior

No response

Actual behavior

No response

Windows is problematic.

Please enable Diagnostic Logging for performance issues and post the log.

I enabled log by this section and try to open nvim-tree by :NvimTreeOpen, but it shows error:

Error executing Lua callback: ...te\pack\packer\start\nvim-tree.lua/lua/nvim-tree/log.lua:15: bad argument #2 to 'format' (value expected)
stack traceback:
        [C]: in function 'format'
        ...te\pack\packer\start\nvim-tree.lua/lua/nvim-tree/log.lua:15: in function 'raw'
        ...te\pack\packer\start\nvim-tree.lua/lua/nvim-tree/log.lua:57: in function 'line'
        ...te\pack\packer\start\nvim-tree.lua/lua/nvim-tree/log.lua:31: in function 'profile_start'
        ...r\start\nvim-tree.lua/lua/nvim-tree/explorer/explore.lua:30: in function 'populate_children'
        ...r\start\nvim-tree.lua/lua/nvim-tree/explorer/explore.lua:70: in function 'explore'
        ...cker\start\nvim-tree.lua/lua/nvim-tree/explorer/init.lua:28: in function '_load'
        ...cker\start\nvim-tree.lua/lua/nvim-tree/explorer/init.lua:21: in function 'new'
        ...e\pack\packer\start\nvim-tree.lua/lua/nvim-tree/core.lua:19: in function 'init'
        ...te\pack\packer\start\nvim-tree.lua/lua/nvim-tree/lib.lua:160: in function 'open'
        ...n\site\pack\packer\start\nvim-tree.lua/lua/nvim-tree.lua:181: in function 'open'
        ...n\site\pack\packer\start\nvim-tree.lua/lua/nvim-tree.lua:224: in function 'toggle'
        ...n\site\pack\packer\start\nvim-tree.lua/lua/nvim-tree.lua:364: in function <...n\site\pack\packer\start\nvim-tree.lua/lua/nvim-tree.lua:363>

I enabled log by this section and try to open nvim-tree by :NvimTreeOpen, but it shows error:

That's great news! It looks like we have some special characters in a file name.

I've hardened the profiling: #1986

Please pull latest master and retest.

nvim-tree.zip

Here is the log. When I press - , it reproduced.

I think we have an answer:

[2023-02-11 14:46:26] [profile] START git toplevel C:\Users\{myusername}\AppData\Local\Temp
[2023-02-11 14:46:26] [git] { "git", "-C", "C:\\Users\\{myusername}\\AppData\\Local\\Temp", "rev-parse", "--show-toplevel" }
fatal: not a git repository (or any of the parent directories): .git
[2023-02-11 14:46:26] [profile] END   git toplevel C:\Users\{myusername}\AppData\Local\Temp 187ms

What is {myusername}? Is that the actual directory name? What does :pwd show?

[2023-02-11 14:46:26] [profile] START explore init C:\Users\{myusername}\AppData\Local\Temp
[2023-02-11 14:46:26] [profile] START explore populate_children C:\Users\{myusername}\AppData\Local\Temp\%2Fclub%2Fitem%2Fparcel%2F0%2F042a0f56cdda683d0d622d7b1d4a3729_63e4a8e0_db5800c5.tmp
[2023-02-11 14:46:26] [profile] END   explore populate_children C:\Users\{myusername}\AppData\Local\Temp\%2Fclub%2Fitem%2Fparcel%2F0%2F042a0f56cdda683d0d622d7b1d4a3729_63e4a8e0_db5800c5.tmp 2ms

What is the name of those %2F files? What does powershell or WSL list them as?

{myusername} is the edited name by myself, not the real username. The real username does not includes any special characters.

name of %2Fclub%2Fitem%2Fparcel%2F0%2F042a0f56cdda683d0d622d7b1d4a3729_63e4a8e0_db5800c5.tmp is actually what it looks like.

>dir /b *.tmp
%2Fclub%2Fitem%2Fparcel%2F0%2F042a0f56cdda683d0d622d7b1d4a3729_63e4a8e0_db5800c5.tmp
%2Fclub%2Fitem%2Fparcel%2F1%2F12e4d7a30d14f3a4675349024e8e12fc_63a2bed8_418100bb.tmp
%2Fclub%2Fitem%2Fparcel%2F3%2F3117149da932e3b9e2cca80a9b38ec64_63ae9d81_f5200012.tmp
%2Fclub%2Fitem%2Fparcel%2F3%2F3d4c4e20b44df0c5b932e14467923596_63e3605c_ee1300b7.tmp
...

I checked the log and found it seems going into a loop from line 17630. It reloaded C:\Users\{myusername}\AppData\Local\Application Data repeatedly and never stopped.

The good news is that there is no resource leak. git looks OK as well.

[2023-02-11 14:46:52] [watcher] event_cb 'C:\Users\{myusername}\AppData\Local\Temp\nvim' 'nvim-tree.log'
[2023-02-11 14:46:52] [watcher] node event scheduled refresh explorer:watch:C:\Users\{myusername}\AppData\Local\Temp\nvim:375
[2023-02-11 14:46:52] [profile] START change dir C:\Users\{myusername}\AppData\Local
[2023-02-11 14:46:52] [profile] START core init C:\Users\{myusername}\AppData\Local

There is a scheduled refresh for nvim-tree.log's directory going on when changing directory. Not necessarily a problem, just interesting.

I checked the log and found it seems going into a loop from line 17630. It reloaded C:\Users{myusername}\AppData\Local\Application Data repeatedly and never stopped.

Those don't look to be scheduled; they are part of the regular reload resulting from the directory change. Please set filesystem_watchers.enable = false and repeat so that we can confirm this.

nvim-tree.zip

Disabled the filesystem_watchers.

nvim-tree.zip

Disabled the filesystem_watchers.

Did vim freeze? It looks OK...
Edit: I see many git attempts.

Please set git.enable = false and repeat.

Does this problem occur in any other directories, or just the Application Data one?

The 1s intervals reminds me of #1831

nvim-tree.zip
Disabled git and still freezed.

This is very slow as I do not have access to a windows environment. I suspect we might have some issues with symlinks here.

Please test this branch with additional logging. Watchers and git disabled please.

cd /path/to/nvim-tree.lua
git pull
git checkout 1961-log

Please also attempt to replicate under WSL. The directory structures are subtly different as shown here #1822

nvim-tree-wsl.zip
nvim-tree-win.zip

Reproduced in WSL and Windows with 1961-log.

It seems that it only occurs in this directory. And I found that Local\Application Data folder is a junction link to its parent folder Local:

C:\Users\regomne\AppData\Local>dir /a App*

2022/12/12  23:51    <JUNCTION>     Application Data [C:\Users\regomne\AppData\Local]
2021/01/06  14:33    <DIR>          Apps

But when I created a similar structure by myself, it didn't reproduce.

I think that's it... a circular reference to itself is not helpful.

We have cycle detection for the initial population, but not this reload. I'll see what I can do.

Bug: special characters e.g. "-" are not being escaped here:

local abs_contains = node.absolute_path and path:match("^" .. node.absolute_path)

Probably not related however will fix as part of this issue.

Reproduced infinite loop locally. Cycle detection resolves.

@regomne I'd be grateful if you tested this fix:

cd /path/to/nvim-tree.lua
git checkout 1961-log
git pull

Inifinite loop fixed! 🎉🎉🎉

Thank you!

Inifinite loop fixed! tadatadatada

Thank you!

Many thanks for all the testing.

@alex-courtis
This commit (4222bb8), introduces a breaking bug for me:

  1. I open one of the project files
  2. call :NvimTreeFindFileToggle
  3. neovim completely freezes
  4. after closing the process, the load on the CPU remains prohibitive and continues to increase gradually, I can only fix this by restarting the computer

I use: arm m1, macos ventura 13.0, nvim 0.8.2

I'm suffering similar problems with @norflin321.
Commit 4222bb8 causes neovim freezing when open a directory. revert that commit fix everything.

I am also experiencing similar issues with nvim-tree throwing the following error for every single directory and file in my project:

Could not start the fs_event watcher for path <path> : EMFILE

Change reverted, please accept my apologies.

@regomne I'd be grateful if you tested a revised fix:

cd /path/to/nvim-tree.lua
git pull
git checkout 1961-cycle-detection-on-refresh-2

Please test:

  • set filesystem_watchers.enable = false
  • :edit a file in a directory that is not opened in the tree
  • :NvimTreeFindFile

OK, I'll test it later tody.

@regomne I'd be grateful if you tested a revised fix:

cd /path/to/nvim-tree.lua
git pull
git checkout 1961-cycle-detection-on-refresh-2

Please test:

  • set filesystem_watchers.enable = false
  • :edit a file in a directory that is not opened in the tree
  • :NvimTreeFindFile

i tried this and didn't notice any problems

@regomne I'd be grateful if you tested a revised fix:

cd /path/to/nvim-tree.lua
git pull
git checkout 1961-cycle-detection-on-refresh-2

Please test:

  • set filesystem_watchers.enable = false
  • :edit a file in a directory that is not opened in the tree
  • :NvimTreeFindFile

All tested and no problems.