Skip to content

race condition in _wait_for_server_to_be_ready #231

@moohbr

Description

@moohbr

Describe the bug

When the remote Neovim server starts up and becomes ready before the 20-second timeout fires, both the readiness probe (probe_server_readiness) and the timeout callback in _wait_for_server_to_be_ready can reach timer:close(). libuv raises an error on the second call because the handle is already closing.

To reproduce

  1. Run nvim -u repro.lua
  2. Connect to any remote host via SSH
  3. Wait for the session to launch. The error appears in the progress view once the server is ready

Expected behavior

No error. If the timer is already closing, the second close() call should be a no-op.

Screenshot/Screencast(s)

Error executing vim.schedule lua callback: .../remote-nvim.nvim/lua/remote-nvim/providers/provider.lua:813: handle 0x55f8ae22c410 is already
  closing
  stack traceback:
      [C]: in function 'close'
      .../remote-nvim.nvim/lua/remote-nvim/providers/provider.lua:813: in function ''
      vim/_editor.lua: in function ''
      vim/_editor.lua: in function <vim/_editor.lua:0>

System information

  • Local OS: Linux (CachyOS) 6.19.3-2-cachyos x86_64
  • Local Neovim version: v0.11.6
  • Remote host OS: Arch Linux 6.18.9-arch1-2 x86_64
  • Remote Neovim version: v0.11.6

Additional context

The race condition is in provider.lua around lines 808–831. Both the success path and the timeout path call timer:stop() + timer:close() with no guard. The fix is a one-liner:

  -- line ~812 (success path)
  if not timer:is_closing() then
    timer:stop()
    timer:close()
  end

  -- line ~828 (timeout path)
  if not timer:is_closing() then
    timer:stop()
    timer:close()
  end

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions