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

Inhibit restart while git operation in progress #2893

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

andyw8
Copy link
Contributor

@andyw8 andyw8 commented Nov 21, 2024

Idea is from https://stackoverflow.com/questions/47901986/how-to-tell-if-a-git-operation-is-in-progress

We want to prevent Ruby LSP from repeatedly restarting when doing a long operation, such as pulling a branch with many new commits. (Normally we restart on changes to Gemfile.lock).

This doesn't fully solve the problem though: For example, if you do a git pull on a large repo, and there are several commits changing Gemfile.lock, index.lock will be created and deleted several times through the pull.

But I believe this will prevent Ruby LSP attempting to boot while there's an incomplete Gemfile.lock.

@andyw8 andyw8 added enhancement New feature or request vscode This pull request should be included in the VS Code extension's release notes labels Nov 21, 2024
Copy link
Contributor

This pull request is being marked as stale because there was no activity in the last 2 months

@andyw8 andyw8 force-pushed the andyw8/inhibit-restart-while-git-operation-in-progress branch from c7662d8 to 79a2917 Compare February 4, 2025 15:08
@github-actions github-actions bot removed the Stale label Feb 5, 2025
@andyw8 andyw8 marked this pull request as ready for review February 5, 2025 19:12
@andyw8 andyw8 requested a review from a team as a code owner February 5, 2025 19:12
@vinistock
Copy link
Member

We want to prevent Ruby LSP from repeatedly restarting when doing a long operation, such as pulling a branch with many new commits. (Normally we restart on changes to Gemfile.lock).
But I believe this will prevent Ruby LSP attempting to boot while there's an incomplete Gemfile.lock.

Can you explain your train of thought here? When you say incomplete Gemfile.lock, when does that happen? Even if you pull many commits, aren't the files update in a single operation at the end?

@andyw8
Copy link
Contributor Author

andyw8 commented Feb 6, 2025

Can you explain your train of thought here? When you say incomplete Gemfile.lock, when does that happen? Even if you pull many commits, aren't the files update in a single operation at the end?

It seems not: https://stackoverflow.com/questions/49362006/does-git-pull-atomically-write-files

Copy link
Member

@vinistock vinistock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tested this and I don't think it fully solves the problem.

As you pointed out in the description, index.lock gets created and deleted multiple times during an operation. By adding it to the list of watchers, it makes us restart multiple times.

Additionally, it forces us to restart even if the contents of the git pull didn't modify the lockfile at all.

I think part of the problem is that we're currently restarting after some git operations (rebase, bisect...) but those watchers aren't playing well with the lockfile watchers.

This is what currently happens:

  1. We detect that the lockfile was updated, we enqueue a restart with the 5 second debounce
  2. Immediately after we also detect that a git operation is happening, so we add the guard to block the restart
  3. Once the git operation is finished, we enqueue a new restart

I think we need to rework how this is happening so that we can ensure the server is only ever restarted once due to these sorts of changes.

We need a kind of debounced semaphore, where the git operations can lock the restart until the user has completed them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request vscode This pull request should be included in the VS Code extension's release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants