Repository navigation
fix: a language server added while several projects are open starts only for the open files of each project, not once more in every other open project - #2225
Merged
lagergren merged 1 commit intoNov 25, 2026
Conversation
…nly for the open files of each project, not once more in every other open project ## What When a language server definition is added, as a user-defined server, a plugin's extension or a test's server, the `LanguageServiceAccessor` of each open project hears of it. Each one went through the open files of every open project, and started the definition's language server in its own project for all of them. With two projects open, a file of project B got a second instance of the server, started in project A with A's root and workspace folders, next to the instance of B, and the files of A got one in B. It also made `LSPSemanticTokenDocumentationProviderTest.testPlainTextOfTwoLanguageServers` fail at times on the Linux jobs, with only the first server's hover (`First line<br>Second line`): runs 45191503838 (2025.3), 45424896318 (2025.3) and 45523015765 (2024.2). ## Cause of the flaky test - In the CI JVM, the shared project of the light tests stays open, and a light test that ran before, such as `SemanticTokensInspectorTest`, gave it an accessor. - So `addSecondServer` started the second server twice: in the test's project, and in the light project for the test's file. A suite of the 238 classes that run before it on CI, followed by the test 400 times, did so in each of the 400 runs. - Both starts connect to the one `MockLanguageServer` of the definition, whose `addRemoteProxy` adds to plain `ArrayList`s. Two starts at once can make one of them fail with `ArrayIndexOutOfBoundsException`. When the failed start is the test project's own, the hover leaves that server out. - A probe that opens the light project first, then runs the test 1000 times, failed once with that exact message, after a start that failed so. Without the light project, 3700 runs passed. - Neither redhat-developer#2207, since the test asks for a hover once, nor `testTheHoverOfALanguageServerWhenTheOtherOneCannotStart`: the 2025.3 failure of run 45191503838 came before that test existed. ## Change `checkCurrentlyOpenFiles` starts the language servers of the added definitions for the open files of the accessor's own project only. The accessor of each other open project does so for the files of its own, as `handleChanged` and `handleRemoved` already deal only with the accessor's own language servers. ## Test `ServerAddedWithSeveralOpenProjectsTest` opens a second project, and adds a language server while a file is open in one of the two projects: - `testTheAddedServerDoesNotStartInAnotherProjectForAFileOfThisOne`: the file of this project gets the language server of this project, and the other project starts none. - `testTheOpenFileOfAnotherProjectGetsTheAddedServerOfThatProject`: the file open in the other project gets the language server of that project, and this project starts none. Both fail without the change, each with the language server that the other project started. ## Behaviour change | Before | After | |---|---| | A language server added while several projects are open starts in each open project for the open files of all of them, so each file gets one instance per open project | It starts in each project for that project's open files only: one instance per file, of the file's own project | Fixes redhat-developer#2224
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2225 +/- ##
==========================================
- Coverage 55.52% 55.50% -0.02%
==========================================
Files 843 843
Lines 35939 35937 -2
Branches 5638 7431 +1793
==========================================
- Hits 19955 19948 -7
Misses 13097 13097
- Partials 2887 2892 +5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Collaborator
Author
|
@coderabbitai review |
Action not completed
|
Collaborator
Author
|
@coderabbitai review |
Action performed
|
lagergren
added a commit
that referenced
this pull request
Nov 25, 2026
… at once without losing one (#2226) ## What `MockLanguageServer` and `MockTextDocumentService` keep the clients of their connections in plain `ArrayList`s. Two starts of a mock server at the same time add to them concurrently. That threw `ArrayIndexOutOfBoundsException` in `MockLanguageServer.addRemoteProxy` and failed one of the starts with `CannotStartServerException`. This is how `LSPSemanticTokenDocumentationProviderTest.testPlainTextOfTwoLanguageServers` lost its second server's hover on CI: #2224 started the server twice, and #2225 fixes that. With #2225 that test no longer starts a server twice, but any test that starts two connections to one mock at once could still hit the same exception. ## Change Test only. - Both lists are now `CopyOnWriteArrayList`s, so concurrent adds, and iteration through `MockLanguageServer.getRemoteProxies()`, are safe. - `MockTextDocumentService.reset()` clears its list instead of replacing it, under the lock that `publishDiagnostics` holds while it takes the first client and rotates the list. ## Tests No new test: the race needs two starts of one mock at once, which #2225 removes from the suite. The evidence is the stack trace that the investigation of #2224 found on CI. The whole suite passes headless on IC 2024.2 and 2025.3: 2,422 tests each, 0 failures, with the 7 skipped tests that were already disabled.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2224
What
With several projects open, adding a language server definition started the server in every open project, for the open files of all open projects. When a definition is added, every project's
LanguageServiceAccessorhears it. ItscheckCurrentlyOpenFileswent through the open files of every open project (ProjectManager.getOpenProjects()), but connected them through its own project. So each file got one instance of the server per open project, and all but one of them had another project's root and workspace folders.It also made
LSPSemanticTokenDocumentationProviderTest.testPlainTextOfTwoLanguageServersfail now and then on Linux CI: 3 of about 520 jobs since 2026-11-23, including #2198 (#2207) and #2222.addSecondServerstarted the second server twice.MockLanguageServer, whoseaddRemoteProxyadds to plainArrayLists. Two concurrent adds threwArrayIndexOutOfBoundsException, and one start failed withCannotStartServerException.#2208 fixed a different cause of the same symptom: the hover cache across language-server changes.
Change
checkCurrentlyOpenFilesstarts the added definitions only for the open files of the accessor's own project. Each open project's accessor does the same for its own files, ashandleChangedandhandleRemovedalready only touch their own project's servers.A project whose accessor doesn't exist yet doesn't connect its open files when a definition is added. Before, another project connected them, to a server of that other project. They connect as usual once a feature or an editor of the project uses LSP4IJ.
Tests
New
ServerAddedWithSeveralOpenProjectsTest(2 tests). It opens a second project and adds a server while a file is open in one of the two projects. Then it checks two things:Red-green: without the fix, both tests fail every run, with the wrapper that the other project started (
expected:<[]> but was:<[LanguageServerWrapper@…]>). With the fix, both pass.Reproduction of the CI failure, with the light project opened first:
The new class,
features.documentation.*,features.semanticTokens.*and*Hover*pass headless on IC 2024.2, 2025.3 and IU 2026.3: 60 tests each. The full suite passes on 2024.2: 2,416 tests, 0 failures, with the 7 skipped tests that were already disabled. Rebased on main at 57bae55, the new class and the hover class pass headless on all three platforms.Not in this PR:
MockLanguageServerandMockTextDocumentService.addRemoteProxystill aren't thread-safe. A test that starts two connections to one mock at once could still hit the same exception.Behaviour change