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

The process doesn't terminate #645

Open
wr9dg17 opened this issue Nov 15, 2023 · 9 comments
Open

The process doesn't terminate #645

wr9dg17 opened this issue Nov 15, 2023 · 9 comments
Labels
enhancement New feature or request

Comments

@wr9dg17
Copy link

wr9dg17 commented Nov 15, 2023

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

@sQVe
Copy link
Contributor

sQVe commented Nov 15, 2023

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.

@wr9dg17
Copy link
Author

wr9dg17 commented Nov 15, 2023

@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?

@fsouza
Copy link
Owner

fsouza commented Nov 15, 2023

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 fsouza added the enhancement New feature or request label Nov 15, 2023
@mantoni
Copy link

mantoni commented Nov 15, 2023

That is something being requested for eslint_d as well here: mantoni/eslint_d.js#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.

@towry
Copy link

towry commented Jan 16, 2024

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

totally forgotten.

@sQVe
Copy link
Contributor

sQVe commented Jan 16, 2024

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

@Tronikelis
Copy link

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,
})

@fsouza
Copy link
Owner

fsouza commented Jun 1, 2024

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.

@Tronikelis
Copy link

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 :)

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

No branches or pull requests

6 participants