prettierd icon indicating copy to clipboard operation
prettierd copied to clipboard

The process doesn't terminate

Open wr9dg17 opened this issue 2 years ago • 9 comments

Hi! I'm using prettierd in my neovim config. As formatting I'm using stevearc/conform.nvim. It works great and fast but I recognized that even after exiting neovim and closing terminal I can see prettierd process still hanging in system monitoring. I usually jump between multiple projects and for every project there is new prettierd process which is normal but they all hang in memory after exiting neovim and closing terminal. After switching to prettier (not prettierd) I can see that processes terminating (as they should) after axiting neovim.

P.S. I'm using mac os

wr9dg17 avatar Nov 15 '23 07:11 wr9dg17

This is the whole point behind prettierd and other similar CLIs. It's a daemonized prettier version, which improves performance substantially since it removes the node startup time.

sQVe avatar Nov 15 '23 07:11 sQVe

@sQVe thank you for reply!

I can understand that, it can improve startup/initialization time and as far as I understood this is some kind of caching mechanism. But in other hand I'm not sure if it is normal to have multiple prettierd processes in memory created couple of days ago. Is there a way to add some job to check how much time passed and kill "stale" processes?

wr9dg17 avatar Nov 15 '23 11:11 wr9dg17

Yeah, right now we don't terminate idle daemons, but it's a good idea. Perhaps we can coordinate with @mantoni to see if they'd be interested in having that feature as part of core_d (something like CORE_D_MAX_IDLE_TIME). To be 100% precise we may need to make some changes in the client too to ensure that it retries/reconnects if the server shuts down right before it can send a request.

If this doesn't make sense within core_d, we can implement it just for prettierd.

fsouza avatar Nov 15 '23 13:11 fsouza

That is something being requested for eslint_d as well here: https://github.com/mantoni/eslint_d.js/issues/236

It makes sense to put the core functionality into core_d so that it can be shared with this project too.

I don't have the time right now to do the leg work, but I'd happily assist, review and integrate.

mantoni avatar Nov 15 '23 15:11 mantoni

企业微信截图_6cd84fb0-3518-4de1-8fbf-176dd61a4ea2

totally forgotten.

towry avatar Jan 16 '24 07:01 towry

I have this workaround, that I've been using for a long while, that you can use until this feature is provided in core_d.

Start by registering an autocmd for a ExitPre event. The callback of the autocmd executes a detached script.

This is how I've set it up:

-- Stop Neovim Daemons.
autocmd('ExitPre', {
  group = augroups.StopNeovimDaemons,
  callback = function()
    vim.fn.jobstart(
      vim.fn.expand('$SCRIPTS') .. '/nvim/stop-nvim-daemons.sh',
      { detach = true }
    )
  end,
})

Next you need to create the stop-nvim-daemons script. This script stops all listed daemons after a set amount of time (in our case 5 minutes).

This is my script that kill both eslint_d and prettierd: https://github.com/sQVe/scripts/blob/14c628dcdfaca4c1e11208c78e124dbcf52c956e/nvim/stop-nvim-daemons.sh#L1-L33

sQVe avatar Jan 16 '24 08:01 sQVe

Or you can have a 5 line simple autocmd with a killall job

vim.api.nvim_create_autocmd("VimLeavePre", {
	callback = function()
		vim.fn.jobstart("killall prettierd eslint_d", { detach = true })
	end,
})

tronikelis avatar Jun 01 '24 07:06 tronikelis

Or you can have a 5 line simple autocmd with a killall job

vim.api.nvim_create_autocmd("VimLeavePre", {
	callback = function()
		vim.fn.jobstart("killall prettierd eslint_d", { detach = true })
	end,
})

That is not a good idea as it'll kill all instances of prettierd regardless of whether or not it was created by the current instance of the editor.

If it works for you, great :D but we can't add it to the readme.

fsouza avatar Jun 01 '24 14:06 fsouza

That is not a good idea as it'll kill all instances of prettierd regardless of whether or not it was created by the current instance of the editor.

Yeah I understand, when I need to work on multiple projects at once I don't close separate nvim instances, so it works for me. This is just how I workaround this, maybe it will be useful to someone else :)

tronikelis avatar Jun 01 '24 14:06 tronikelis