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

Fix for a race condition when starting language server #1780

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

analizator1
Copy link

@analizator1 analizator1 commented Jan 12, 2025

In the following scenario:

  1. Run vim with https://github.com/vim-ctrlspace/vim-ctrlspace plugin
  2. open a workspace which contains a few buffers, for example C++ source/header files (can be in a single tab)

What happens from time to time is that LSP server (in my case clangd) started more than once. With more than one running clangd process, YouCompleteMe does not work at all, because it tries to use a server that is not initialized - initialize request was sent to another one. Workaround: quit vim, kill ycmd and clangd processes, start vim again.

The way I fixed it is that _server_started is only accessed within _server_info_mutex and only the first thread calls StartServer(). Note that it required to partially revert #1434. Given that _server_started is now accessed only within the mutex, it does not make any sense for _AwaitServerMessages to access it. For additional rationale about it, see 6b6084a commit message.


This change is Reviewable

…) to complete

This is a UT fixup for a change in _AwaitServerMessages.

Note that ycm-core#1434 (comment) is not exactly correct together with ycm-core#1434.
Quote:
> (...) Note that the java completer has a ton of setup to do before it gets to the super().StartServer().

It's true that it has some additional tasks (wiping out workspace) before it calls *super()._StartServerNoLock()*. But
PR 1434 doesn't address it - wiping workspace is called from JavaCompleter.StartServer() at which point _server_started
is already True, so the following part from that PR in _AwaitServerMessages():

-return self._initialize_event.is_set()
+return not self._server_started or self._initialize_event.is_set()

did not make it return True. In other words, ycm-core#1434 seems to not address the JavaCompleter issue, but only the issue with
potentially long extra conf Settings(). However according to
ycm-core#1433 (comment) this should rather be solved by increasing
MESSAGE_POLL_TIMEOUT. Anyway, one of the first things we do from OnFileReadyToParse() when server is not healthy is
setting _server_started to True.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant