mirror of
https://github.com/neovim/neovim.git
synced 2026-07-13 12:50:31 +00:00
feat(health): report ulimit info
Problem: Nvim shows `(libuv) kqueue(): Too many open files` on macos. ref https://github.com/neovim/neovim/issues/40238 Solution: Add a healthcheck for this situation.
This commit is contained in:
20
runtime/lua/vim/_core/proc.lua
Normal file
20
runtime/lua/vim/_core/proc.lua
Normal file
@@ -0,0 +1,20 @@
|
||||
-- OS/process utils.
|
||||
|
||||
local M = {}
|
||||
|
||||
--- Counts (approximate) open file descriptors for this process. Works on Linux/macOS/BSD.
|
||||
---@return integer? # Number of open fds, or nil if `/dev/fd` failed (fds exhausted, or unavailable/Windows).
|
||||
function M.count_open_fds()
|
||||
local n = 0
|
||||
for _, _, err in vim.fs.dir('/dev/fd', { err = true }) do
|
||||
-- If `/dev/fd` scan failed (e.g. EMFILE when fds exhausted), count would be misleading.
|
||||
if err then
|
||||
return nil
|
||||
end
|
||||
n = n + 1
|
||||
end
|
||||
-- Discount the scan's own descriptor.
|
||||
return math.max(0, n - 1)
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user