[BUG] Job: `cannot resume dead coroutine` with `maximum-results`

Open
#327 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
lua
Domain
tooling

Research direction

Reproduce the failure with the provided Job example, then inspect lua/plenary/job.lua around shutdown at line 218 and the callback near line 343. Trace how vim.wait and cleanup interact when find reports permission errors with maximum_results. Done means this scenario completes without the cannot resume dead coroutine error.

Written by the indexing model from the issue text.

Description

I found a bug with the Job class: if you set maximum_results and the process encounters an error during execution, you will get this error message:

Error executing luv callback:
cannot resume dead coroutine
stack traceback:
        [builtin#36]: at 0x57ac5f2f4ad0
        [C]: in function 'wait'
        .../site/pack/packer/start/plenary.nvim/lua/plenary/job.lua:218: in function 'shutdown'
        .../site/pack/packer/start/plenary.nvim/lua/plenary/job.lua:343: in function <.../site/pack/packer/start/plenary.nvim/lua/plenary/job.lua:342>

You can recreate it reliably with this example:

local Job = require("plenary.job")

Job:new({
  command = "find",
  args = {"/", "-iname", "e"},
  maximum_results = 10,
  on_start = function ()
    print("start")
  end,
  on_stdout = function(_, data, _)
    print(data)
  end,
  on_stderr = function(_, data, _)
    print(data)
  end,
  on_exit = function(_, code, _)
    print("exit", code)
  end,
}):start()

I am trying to fix it but it's proving more difficult than I anticipated. As far as I can see, the error is caused by vim.wait returning after everything has already been cleaned up. It will work fine for a normally executing process with a clean exit, but not in this situation where a process has errors. At least this applies to using the find command when it searches directories that you don't have permissions to.

Dominant language
Lua
Stars
3.5k
Forks
340
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nvim-lua/plenary.nvim

All issues in nvim-lua/plenary.nvim

Similar issues

More Lua issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.