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

ruff server not closing with neovim instances #11207

Closed
akthe-at opened this issue Apr 29, 2024 · 7 comments · Fixed by #11222
Closed

ruff server not closing with neovim instances #11207

akthe-at opened this issue Apr 29, 2024 · 7 comments · Fixed by #11222
Assignees
Labels
bug Something isn't working server Related to the LSP server

Comments

@akthe-at
Copy link

Ruff: 0.4.2
OS: Windows 10
Terminal: Wezterm - Latest Nightly
Shell: Powershell Core 7.4.2
Neovim Build - Latest nightly (and each nightly over the past 3-4 days I've noticed this)

Hello All...I feel like this is going to be kind of a barebones bug report and I am sorry about that.

I have been using the new ruff server in lieu of ruff_lsp with neovim and noticed that there might be an issue with ruff.exe not always being terminated when you close a neovim instance. I have tried to consistently reproduce the bug and I have failed but I noticed that every once in a while I can check my processes and there will be a plethora of ruff.exe running even though I might only have 1 or 2 neovim instances or buffers open.

image

I don't think I ever noticed this during my time using ruff_lsp.

Love what you all do, just wanted to try and keep you aware since ruff server is in alpha.

@MichaReiser MichaReiser added the server Related to the LSP server label Apr 29, 2024
@dhruvmanila
Copy link
Member

Good catch! Thanks for opening this issue. It's happening on macOS as well. And it isn't specific to Neovim, I'm seeing it in VS Code as well.

Screen.Recording.2024-04-30.at.13.35.37.mov

@dhruvmanila dhruvmanila added the bug Something isn't working label Apr 30, 2024
snowsignal added a commit that referenced this issue May 3, 2024
## Summary

Fixes #11207.

The server would hang after handling a shutdown request on
`IoThreads::join()` because a global sender (`MESSENGER`, used to send
`window/showMessage` notifications) would remain allocated even after
the event loop finished, which kept the writer I/O thread channel open.

To fix this, I've made a few structural changes to `ruff server`. I've
wrapped the send/receive channels and thread join handle behind a new
struct, `Connection`, which facilitates message sending and receiving,
and also runs `IoThreads::join()` after the event loop finishes. To
control the number of sender channels, the `Connection` wraps the sender
channel in an `Arc` and only allows the creation of a wrapper type,
`ClientSender`, which hold a weak reference to this `Arc` instead of
direct channel access. The wrapper type implements the channel methods
directly to prevent access to the inner channel (which would allow the
channel to be cloned). ClientSender's function is analogous to
[`WeakSender` in
`tokio`](https://docs.rs/tokio/latest/tokio/sync/mpsc/struct.WeakSender.html).
Additionally, the receiver channel cannot be accessed directly - the
`Connection` only exposes an iterator over it.

These changes will guarantee that all channels are closed before the I/O
threads are joined.

## Test Plan

Repeatedly open and close an editor utilizing `ruff server` while
observing the task monitor. The net total amount of open `ruff`
instances should be zero once all editor windows have closed.

The following logs should also appear after the server is shut down:

<img width="835" alt="Screenshot 2024-04-30 at 3 56 22 PM"
src="https://github.com/astral-sh/ruff/assets/19577865/404b74f5-ef08-4bb4-9fa2-72e72b946695">

This can be tested on VS Code by changing the settings and then checking
`Output`.
@ShIRannx
Copy link

ShIRannx commented May 5, 2024

The problem persists in neovim after ruff 0.4.3.

@snowsignal
Copy link
Contributor

@ShIRannx I've found the cause for that and opened a follow-up fix: #11291.

@danielhollas
Copy link

Hi @snowsignal I am still seeing this problem with ruff 0.4.5 and neovim 0.9.5 on Linux Fedora 39.

@dhruvmanila
Copy link
Member

@danielhollas Hi, can you open a new issue with the logs? I tried it on macOS with Ruff 0.4.5 and Nvim 0.10.0 and it works as expected. Can you also try it with Nvim 0.10.0?

@danielhollas
Copy link

Hi @dhruvmanila 👋

happy to do more investigation, but would you mind explaining how to get the logs? (Sorry, I am new to neovim, and LSP in general).

@dhruvmanila
Copy link
Member

No worries. You can find the file path using vim.lsp.get_log_path() function. You can then copy paste the relevant lines (usually would be at the end of the file) related to ruff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working server Related to the LSP server
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants