f-person / auto-dark-mode.nvim

A Neovim plugin for macOS, Linux & Windows that automatically changes the editor appearance based on system settings.
GNU General Public License v3.0
306 stars 23 forks source link

Process failed to start: too many open files #4

Closed confusedkernel closed 1 year ago

confusedkernel commented 1 year ago

Hello, I was using auto-dark-mode.nvim and encountered this issue. Whenever I open the terminal using toggleterm.nvim it shows this error.

stack traceback:
^I[C]: in function 'jobstart'
^I...im/lazy/auto-dark-mode.nvim/lua/auto-dark-mode/utils.lua:8: in function 'start_job'
^I...vim/lazy/auto-dark-mode.nvim/lua/auto-dark-mode/init.lua:23: in function 'callback'
^I...im/lazy/auto-dark-mode.nvim/lua/auto-dark-mode/utils.lua:48: in function 'check_is_root'
^I...vim/lazy/auto-dark-mode.nvim/lua/auto-dark-mode/init.lua:16: in function 'check_is_dark_mode'
^I...vim/lazy/auto-dark-mode.nvim/lua/auto-dark-mode/init.lua:48: in function <...vim/lazy/auto-dark-mode.nvim/lua/auto-dark-mode/init.lua:47> function: builtin#18 Vim:E903: Process failed to start: too many open files: "/usr/local/bin/fish"

The screenshot below is the amount of files I currently opened. Is there any reason as to why this is happening and how can I resolve this issue?

neovim broken leh
f-person commented 1 year ago

"Process failed to start: too many open files" is a Unix issue that indicates too many files were open. I'm not really sure what causes this issue, but it could either indicate something wrong with the configuration or the check_is_root function 🤔

confusedkernel commented 1 year ago

Huh, seems like some people are also experiencing this issue with other plugins? https://github.com/folke/trouble.nvim/issues/173 https://github.com/neovim/neovim/issues/14192

My current fix is that I added ulimit -n 2048 to my shell config, but still not sure what exactly went wrong.

Update: it still doesn't work, I thought it did but then it didn't.

f-person commented 1 year ago

Hmm, weird stuff 🤔 Not sure what I can do here. We can keep the issue open for a while for better discoverability. The plugin does open files for reading. I could perhaps add some error handling so that you don't get annoyed by the error messages, but it's still not a fix ¯\(ツ)/¯ If you could comment a min. reproducible config, that would be of great help :)

leana8959 commented 1 year ago

Hello 👋

I just read the source code. I wonder if this is caused by the fact that the sub processes aren't closed after each invocation.

https://github.com/f-person/auto-dark-mode.nvim/blob/79a614f12ec21f99123c61a9b85e441238455113/lua/auto-dark-mode/utils.lua#L6-L28

In the function start_job, there's vim.fn.jobstart() but no vim.fn.jobstop() to close the spawned tasks.

There is indeed vim.fn.chanclose(), though I wonder if it only closes the handle to stdout instead of closing the subprocess entirely.

This would make sense, since the error message says "Process failed to start: too many open files: "/usr/local/bin/fish"", which could potentially mean that the shell invoked isn't closed.

I hope this could help diagnose root cause of the problem!

f-person commented 1 year ago

Hi, @leana8959! Thank you, that's pretty useful; I'll take a look at the job API and see if maybe I missed something ^_^

f-person commented 1 year ago

@nottyl, could you try the fix/jobstop branch and see if that fixes your issue? I'm not sure it's actually going to do anything since jobstop seems to forcefully terminate the process (which should be closed anyways), but it could :)

confusedkernel commented 1 year ago

unfortunately, no... this is an odd bug to be honest

Screenshot 2023-05-31 at 17 15 48
f-person commented 1 year ago

That's unfortunate :( As a workaround, I would suggest either disabling the plugin in toggleterm or considering using a separate top-down terminal. I use iTerm2 triggered on command+shift+enter and wezterm as a "work terminal". I've been using this setup for a couple of years now, and it works perfectly for me (I prefer to always have an open terminal with preserved state, not only inside nvim)

leana8959 commented 1 year ago

@nottyl Could you provide a minimum configuration that reproduces the error?

You can use nvim -u to specify a init.lua that's separate from your current config, and set NVIM_APPNAME to adm_dbg for example (learn more :h NVIM_APPNAME)

Have a nice day :)

f-person commented 1 year ago

hey @nottyl, hope you're having a lovely day! i think the latest version should resolve your issue! lmk if it works for you!

f-person commented 1 year ago

gonna close this issue for now, i belive it should be fixed! feel free to reopen in case it's not :)