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

Use unique IDs for registering watchers #3144

Merged
merged 1 commit into from
Feb 6, 2025

Conversation

vinistock
Copy link
Member

@vinistock vinistock commented Feb 6, 2025

Motivation

Closes #3137

We were using the same registration ID for two different file watchers. That made VS Code override the entry, but one of them became a dangling object that didn't get appropriately cleaned up when the LSP shuts down.

Because that old file watcher was still active, the LSP client itself was not cleared either as a reference was still being held and then notifications for didChangeWatchedFiles were sent to a client that was already stopped, resulting in the Notify file events failed message.

We should always use unique IDs when registering file watchers.

Implementation

I did 3 small things:

  1. Ensured unique IDs for registering the watchers
  2. Started watching .rubocop, which we watched before but I missed in my refactor PR
  3. Started ensuring that we're only processing changes once

The last point is necessary because add-ons may register for watching the same patterns as one another or as the Ruby LSP and that results in duplicate changes being sent to the server.

The most optimal solution is #3145, but that is going to require more effort, so let's just fix the issue for now.

Automated Tests

Added a test and verified manually that the issue is gone.

@vinistock vinistock added bugfix This PR will fix an existing bug server This pull request should be included in the server gem's release notes labels Feb 6, 2025 — with Graphite App
@vinistock vinistock self-assigned this Feb 6, 2025
Copy link
Member Author


How to use the Graphite Merge Queue

Add the label graphite-merge to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@vinistock vinistock requested review from andyw8 and st0012 February 6, 2025 15:33
@vinistock vinistock marked this pull request as ready for review February 6, 2025 15:42
@vinistock vinistock requested a review from a team as a code owner February 6, 2025 15:42
@vinistock vinistock force-pushed the 02-06-use_unique_ids_for_registering_watchers branch from db19077 to e2f2a52 Compare February 6, 2025 15:42
lib/ruby_lsp/server.rb Outdated Show resolved Hide resolved
lib/ruby_lsp/server.rb Outdated Show resolved Hide resolved
lib/ruby_lsp/server.rb Outdated Show resolved Hide resolved
@vinistock vinistock force-pushed the 02-06-use_unique_ids_for_registering_watchers branch from e2f2a52 to 1b4c1af Compare February 6, 2025 15:52
@vinistock vinistock added the graphite-merge Ship this PR using Graphite's merge queue label Feb 6, 2025
Copy link
Member Author

vinistock commented Feb 6, 2025

Merge activity

  • Feb 6, 10:54 AM EST: The merge label 'graphite-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Feb 6, 11:39 AM EST: A user added this pull request to the Graphite merge queue.
  • Feb 6, 12:08 PM EST: A user merged this pull request with the Graphite merge queue.

@andyw8
Copy link
Contributor

andyw8 commented Feb 6, 2025

I expect this will be a breaking-change?

@vinistock
Copy link
Member Author

I expect this will be a breaking-change?

None of the add-ons are currently using that helper method. Even Standard and RuboCop are just building the request by hand. Do you feel like it's too risky to not mark as breaking change?

@andyw8
Copy link
Contributor

andyw8 commented Feb 6, 2025

It probably has minimal impact, but we don't know what private or under-development might be using it. Your call.

@vinistock vinistock force-pushed the 02-06-use_unique_ids_for_registering_watchers branch 2 times, most recently from 10ca2ff to 194f9ce Compare February 6, 2025 16:12
@vinistock
Copy link
Member Author

Alright, I made the API compatible with the old style to avoid having to cut a breaking change just for this.

I checked every add-on published to rubygems with the ruby-lsp prefix and no one was using it, but better to not make unannounced breaking changes.

@andyw8
Copy link
Contributor

andyw8 commented Feb 6, 2025

Nice solution.

### Motivation

Closes #3137

We were using the same registration ID for two different file watchers. That made VS Code override the entry, but one of them became a dangling object that didn't get appropriately cleaned up when the LSP shuts down.

Because that old file watcher was still active, the LSP client itself was not cleared either as a reference was still being held and then notifications for `didChangeWatchedFiles` were sent to a client that was already stopped, resulting in the `Notify file events failed` message.

We should always use unique IDs when registering file watchers.

### Implementation

I did 3 small things:

1. Ensured unique IDs for registering the watchers
2. Started watching `.rubocop`, which we watched before but I missed in my refactor PR
3. Started ensuring that we're only processing changes once

The last point is necessary because add-ons may register for watching the same patterns as one another or as the Ruby LSP and that results in duplicate changes being sent to the server.

The most optimal solution is #3145, but that is going to require more effort, so let's just fix the issue for now.

### Automated Tests

Added a test and verified manually that the issue is gone.
@graphite-app graphite-app bot force-pushed the 02-06-use_unique_ids_for_registering_watchers branch from 194f9ce to d48edf2 Compare February 6, 2025 16:40
@graphite-app graphite-app bot merged commit d48edf2 into main Feb 6, 2025
42 checks passed
@graphite-app graphite-app bot deleted the 02-06-use_unique_ids_for_registering_watchers branch February 6, 2025 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This PR will fix an existing bug graphite-merge Ship this PR using Graphite's merge queue server This pull request should be included in the server gem's release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Notify file events failed - Client is not running
2 participants