Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plenary.job:shutdown(code, signal) not terminating process #156

Open
Charly6596 opened this issue May 12, 2021 · 3 comments
Open

Plenary.job:shutdown(code, signal) not terminating process #156

Charly6596 opened this issue May 12, 2021 · 3 comments

Comments

@Charly6596
Copy link

Charly6596 commented May 12, 2021

Maybe I'm not understanding the concept of Job or shutdown, but I expect the started process to finish when I shutdown the job with the shutdown function (or at least send the signal given as parameter), but it's not doing either for some processes.

I have set up a simple configuration to reproduce this issue

  1. Create the following file, config.lua
--- use your own way to load plugins
vim.fn['plug#begin']('~/.vim/plugged')
  vim.fn["plug#"]('nvim-lua/plenary.nvim')
vim.fn['plug#end']()


--- @type Job
local Job = require("plenary.job")

MyJob = Job:new({
        command = "mycommand.sh",
        on_exit = vim.schedule_wrap(function(self, code, signal)
          print(string.format("PID: %d | code: %d | signal: %d", self.pid, code, signal))
        end),
      })

MyJob:start()
  1. Start neovim with neovim -u config.lua
  2. Get the process PID with :lua print(MyJob.pid)
  3. Watch the process system calls with sudo strace -p <pid> where is the pid obtained in the previous step.
  4. Shutdown the process in neovim with :lua MyJob:shutdown(0, 3). I expect the process to receive a SIGQUIT(3) signal but nothing appears in the strace output. It doesn't matter if you run shutdown without arguments or with another signals, still no output in strace. However, shutdown executes on_exit correctly and prints the following PID: <pid> | code: 0 | signal: 3.
  5. To verify that strace should output something when it receives a signal, run kill -n 3 <pid>
    image
    Alternatively, you could also use :lua vim.loop.kill(MyJob.pid, 3)

Am I doing something wrong? What should I use in order to stop the process instead?

Just for some context, this is where I'm trying to use it, right now using vim.loop.kill as a workaround (in that code I'm killing a process started by the job instead), but I'm expecting the following to work

function M.stop()
  if job then
    job:shutdown() -- or maybe use a signal to terminate the process
end

I'm getting the following behaviour instead: (almost a copy of this comment in a PR for flutter-tools.nvim
Execute a command to start the job: (The first one is the job, second one the child process)
image

Both processes are in the process tree, bash and dart (the parent of zsh is my terminal)
image

Executing the stop lua function inside neovim executes the on_exit function, but the processes are still there (both of them actually, same tree)
image

After exiting the processes, instead of terminating, are detached and moved to the root (systemd):
image

@Charly6596 Charly6596 changed the title Plenary.Job:shutdown not terminating process Plenary.job:shutdown(code, signal) not terminating process May 12, 2021
@oberblastmeister
Copy link
Collaborator

oberblastmeister commented May 14, 2021

This is a known issue with the current job implementation. See #101 for info and tj is doing a pr #129

@aaronik
Copy link

aaronik commented Apr 30, 2024

I'm still running into this issue

@kuro337
Copy link

kuro337 commented Aug 8, 2024

Same, issue still exists

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants