Skip to content

bug: macOS sleep/resume can trigger EMFILE and spam long plenary Job stack traces (copilot token refresh) #2815

@Jonkimi

Description

@Jonkimi

Describe the bug

Repeated/large error output like: ...plenary/job.lua:406: Failed to spawn process: { ... pid = "EMFILE: too many open files", ... } (full stack trace repeated many times), makes Neovim usable.

Error executing vim.schedule lua callback: ...al/share/nvim/site/lazy/plenary.nvim/lua/plenary/job.lua:406: Failed to spawn process: {
  _additional_on_exit_callbacks = {},
  _shutdown_check = <userdata 1>,
  _stderr_results = {},
  _stdout_results = {},
  _user_on_exit = <function 1>,
  args = { "-sSL", "-D", "/tmp/plenary_curl_8e9f49e1.headers", "--compressed", "-X", "GET", "-H", "Accept: application/json", "-H", "Authorization: token ghu_1u5WGtv7H1bI3ICzAw3m
CNh9d5O4JG3CGaof", "https://api.github.com/copilot_internal/v2/token" },
  command = "curl",
  enable_handlers = true,
  enable_recording = true,
  interactive = true,
  pid = "EMFILE: too many open files",
  stderr = <userdata 2>,
  stdin = <userdata 3>,
  stdout = <userdata 4>,
  user_data = {},
  <metatable> = <1>{
    __index = <table 1>,
    _create_uv_options = <function 2>,
    _execute = <function 3>,
    _pipes_are_closed = <function 4>,
    _prepare_pipes = <function 5>,
    _reset = <function 6>,
    _shutdown = <function 7>,
    _stop = <function 8>,
    add_on_exit_callback = <function 9>,
    after = <function 10>,
    after_failure = <function 11>,
    after_success = <function 12>,
    and_then = <function 13>,
    and_then_on_failure = <function 14>,
    and_then_on_failure_wrap = <function 15>,
    and_then_on_success = <function 16>,
    and_then_on_success_wrap = <func 17>,
    and_then_wrap = <function 18>,
    chain = <function 19>,
    chain_status = <function 20>,
    co_wait = <function 21>,
    is_job = <function 22>,
    join = <function 23>,
    new = <function 24>,
    pid = <function 25>,
    result = <function 26>,
    send = <function 27>,
    shutdown = <function 28>,
    start = <function 29>,
    stderr_result = <function 30>,
    sync = <function 31>,
    wait = <function 32>
  }
}
stack traceback:
        ...al/share/nvim/site/lazy/plenary.nvim/lua/plenary/job.lua:406: in function '_execute'
        ...al/share/nvim/site/lazy/plenary.nvim/lua/plenary/job.lua:449: in function 'start'
        ...l/share/nvim/site/lazy/plenary.nvim/lua/plenary/curl.lua:323: in function 'get'
        ...m/site/lazy/avante.nvim/lua/avante/providers/copilot.lua:188: in function 'refresh_token'
        ...m/site/lazy/avante.nvim/lua/avante/providers/copilot.lua:339: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>
stack traceback:
        [C]: in function 'error'
        ...al/share/nvim/site/lazy/plenary.nvim/lua/plenary/job.lua:406: in function '_execute'
        ...al/share/nvim/site/lazy/plenary.nvim/lua/plenary/job.lua:449: in function 'start'
        ...l/share/nvim/site/lazy/plenary.nvim/lua/plenary/curl.lua:323: in function 'get'
        ...m/site/lazy/avante.nvim/lua/avante/providers/copilot.lua:188: in function 'refresh_token'
        ...m/site/lazy/avante.nvim/lua/avante/providers/copilot.lua:339: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

To reproduce

  • Neovim running with avante.nvim + copilot provider enabled on macOS.
  • Put macOS to sleep (close lid / sleep) for a long time(one day maybe), then wake the machine again.
  • After wake, avante.nvim triggers copilot token refreshes and plenary Job spawn fails with "EMFILE: too many open files", spamming the Neovim message area with full plenary stack traces.

Expected behavior

Handle spawn errors more gracefully like #2356 or Exafunction/windsurf.nvim#297

Installation method

Use lazy.nvim:

--   "yetone/avante.nvim",
-- if you want to build from source then do `make BUILD_FROM_SOURCE=true`
-- ⚠️ must add this setting! ! !
build = function()
	-- conditionally use the correct build system for the current OS
	if vim.fn.has("win32") == 1 then
		return "powershell -ExecutionPolicy Bypass -File Build.ps1 -BuildFromSource false"
	else
		return "make BUILD_FROM_SOURCE=true"
	end
end,
event = "VeryLazy",
version = false, -- Never set this value to "*"! Never!
---@module 'avante'
---@type avante.Config
opts = {
	-- add any opts here
	-- for example
	provider = "copilot",
	-- provider = "openai",
	providers = {
		gemini = {
			model = "gemini-2.5-flash"
		}
	},
},
dependencies = {
	"nvim-lua/plenary.nvim",
	"MunifTanjim/nui.nvim",
	--- The below dependencies are optional,
	"echasnovski/mini.pick", -- for file_selector provider mini.pick
	"nvim-telescope/telescope.nvim", -- for file_selector provider telescope
	"hrsh7th/nvim-cmp", -- autocompletion for avante commands and mentions
	"ibhagwan/fzf-lua", -- for file_selector provider fzf
	"stevearc/dressing.nvim", -- for input provider dressing
	"folke/snacks.nvim", -- for input provider snacks
	"nvim-tree/nvim-web-devicons", -- or echasnovski/mini.icons
	"zbirenbaum/copilot.lua", -- for providers='copilot'
	{
		-- support for image pasting
		"HakonHarnes/img-clip.nvim",
		event = "VeryLazy",
		opts = {
			-- recommended settings
			default = {
				embed_image_as_base64 = false,
				prompt_for_file_name = false,
				drag_and_drop = {
					insert_mode = true,
				},
				-- required for Windows users
				use_absolute_path = true,
			},
		},
	},
	{
		-- Make sure to set this up properly if you have lazy=true
		"MeanderingProgrammer/render-markdown.nvim",
		opts = {
			file_types = { "markdown", "Avante" },
		},
		ft = { "markdown", "Avante" },
	},
},

Environment

NVIM v0.10.4
Build type: Release
LuaJIT 2.1.1736781742
Run "nvim -V1 -v" for more info

Repro

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

require("lazy.minit").repro({
  spec = {
    -- add any other plugins here
  },
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    StalebugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions