Job keeps running after neovim exits

Open
#328 4 comments 1 reaction 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

Research direction

Start by inspecting the plenary.job entry points used here: Job:new, j:start(), and the detach option. Reproduce the process-parent behavior on Neovim exit, then trace how job cleanup is handled and verify that a non-detached job exits with Neovim rather than being reparented.

Written by the indexing model from the issue text.

Description

I have an external program I want to run that runs forever, and very rarely prints a thing on stdout I want to handle.

This works all works fine

local Job = require("plenary.job")

local j = Job:new({
  command = "/path/to/my/thing",
  on_stdout = function(_, msg)
    process(msg)
    end
  end,
})

j:start()

and starts the external process with the parent being neovim as I would expect.

~> ps -l -p 43471,43782
  UID   PID  PPID        F CPU PRI NI       SZ    RSS WCHAN     S             ADDR TTY           TIME CMD
  501 43471 43334     4006   0  31  0  5525556  42416 -      S+                  0 ttys000    0:01.56 nvim test.lua
  501 43782 43471     4006   0  31  0  4560568   9424 -      S+                  0 ttys000    0:00.05 /path/to/my/thing

However, when I quit neovim, the external process is not stopped, and it's parent has changed to 1

~> ps -l -p 43471,43782
  UID   PID  PPID        F CPU PRI NI       SZ    RSS WCHAN     S             ADDR TTY           TIME CMD
  501 43782     1     4006   0  31  0  4560568   9424 -      S                   0 ttys000    0:00.05 /path/to/my/thing

I'm not using the detach flag on job, so I expected the process to die when the parent process died.

I suppose I could register an autocomand to do something at vim exit (maybe? I'm just assuming there is an autocommand for that but don’t know what it is or if it exists for real), but that seems hacky. Is there another way to get this process to automatically exit when neovim itself exists?

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.