Git Product home page Git Product logo

Comments (8)

stevearc avatar stevearc commented on June 7, 2024 1

Alright, I'll give that a shot when I get a chance

from overseer.nvim.

stevearc avatar stevearc commented on June 7, 2024

Hmmmm...this is very interesting. I haven't had any such issues; all the long-running tasks that I use are terminated when I exit neovim. I know that the processes started with termopen() are slightly different from those started with jobstart(), and in general there has been some iteration on how Neovim handles child processes.

Would it be possible to come up with a minimal script or example where I can reproduce the issue?

from overseer.nvim.

jfpedroza avatar jfpedroza commented on June 7, 2024

Ok, so far I have only been able to reproduce it on a very specific case: a make command running a docker command.

The task is killed if run make with a non-docker command, and also when running the docker command directly. However, if I run a make command that runs a docker command, and close nvim, neither the make process nor the docker process is killed.

Tried it with a simple make recipe that runs docker logs -f on a container.

from overseer.nvim.

stevearc avatar stevearc commented on June 7, 2024

Well I have some additional information. When vim exits it sends all of its open terminals (opened with termopen) a SIGHUP. Turns out, make ignores SIGHUP, though I can't find any documentation about this. This isn't so uncommon, as daemon processes often use SIGHUP to trigger reloading the config from disk, or similar. When you stop the task directly in overseer (with jobstop) it sends a SIGHUP, followed after a short pause by SIGTERM, which does successfully kill it (I believe that is this KILL_TIMEOUT_MS at work). Interestingly, processes started with jobstart are killed with SIGTERM on exit. This appears to be an intentional difference in Neovim's handling of PTY child processes. Another interesting inconsistency: when I open a terminal with :terminal and run the make command directly, the process receives a SIGHUP signal followed by another SIGHUP sent by the kernel on vim exit, which in this case does correctly kill the process. This last behavior I do not understand.

I've put in some logic that explicitly calls jobstop() when vim is exiting. In most cases, this doesn't change anything. If you have a task like make that swallows the SIGHUP, it will cause Neovim to hang for about 2 seconds on exit as it cleans up the children. I think this is an acceptable tradeoff for now.

Long-term, I'm thinking of making a different strategy that directly uses uv.spawn instead of termopen(). That should give us more direct control over handling the child processes.

from overseer.nvim.

stevearc avatar stevearc commented on June 7, 2024

While investigating a strategy that uses uv.spawn I determined that it doesn't make much sense. It would be better to use jobstart() because that handles a lot of the process management and cross-platform logic that we would need anyway. Both of the strategies (terminal & jobstart) should use the above logic of waiting for 2 seconds if necessary and then killing child processes.

Please re-open if the original issue is not resolved.

from overseer.nvim.

jfpedroza avatar jfpedroza commented on June 7, 2024

The change kills the make command, but since what I run is a docker container, the container keeps running on exit.

I don't think there is a way to stop the container as well, so it can be left as-is.

from overseer.nvim.

willruggiano avatar willruggiano commented on June 7, 2024

Related, although I don't think this is strictly the purview of overseer.nvim. Adding comments here in case it sparks additional inspiration.

One of my .vscode/tasks.json entries is:

    {
      "label": "Devenv",
      "type": "shell",
      "command": "devenv",
      "args": ["up"]
    }

which starts devenv. When I exit neovim, the process that devenv spawns (in my case: postgres) is still running and I have to manually pkill -f postgres to kill it.

I've resorted to a project-local "plugin" in .nvim/devenv.lua:

local ok, overseer = pcall(require, "overseer")
if ok and not vim.env.NVIM_DISABLE_DEVENV_EXT then
  vim.api.nvim_create_user_command("Devenv", function()
    local devenv = overseer.new_task({
      cmd = "devenv up",
      components = { "default" },
    })
    devenv:start()

    vim.api.nvim_create_autocmd("VimLeavePre", {
      callback = function()
        -- devenv:stop() -- kills devenv but not postgres
        overseer.new_task({
          cmd = "pkill -f postgres"
        }):start()
      end,
    })
  end, { desc = "devenv" })
end

from overseer.nvim.

melMass avatar melMass commented on June 7, 2024

+1 for adding a way to notify about running tasks on quit

from overseer.nvim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.