Repository navigation
Description
Version: main at 7c6d061. The code dates from the $/progress support (83a5729, 2024-03-31), so every release has it.
What happens
In a headless application, as in the tests of a plugin built on LSP4IJ or a headless run of the IDE, a language server that sends $/progress stalls its own connection: LSP4IJ reads no further message from it, so every request to it waits forever.
LanguageClientImpl.notifyProgress is called on the LSP4J thread that reads the messages of the language server. It calls LSPProgressManager.notifyProgress, whose createTask starts the progress with ProgressManager.getInstance().run(new Task.Backgroundable(...)). With a UI, the platform runs that task on a pooled thread. Headless, it runs it synchronously in the calling thread (CoreProgressManager.runProcessWithProgressInCurrentThread). The task loops on LSPProgressInfo.getNextProgressNotification() until the progress ends, but the report and end notifications can only be read by the thread that now runs the loop.
The reading thread, from a thread dump of such a hang:
"LS-…#listener-0" TIMED_WAITING
at java.util.concurrent.LinkedBlockingDeque.pollFirst(LinkedBlockingDeque.java:515)
at com.redhat.devtools.lsp4ij.features.progress.LSPProgressInfo.getNextProgressNotification(LSPProgressInfo.java:69)
at com.redhat.devtools.lsp4ij.features.progress.LSPProgressManager$1.run(LSPProgressManager.java:107)
at com.intellij.openapi.progress.impl.CoreProgressManager.startTask(CoreProgressManager.java:477)
…
at com.intellij.openapi.progress.impl.CoreProgressManager.runProcessWithProgressInCurrentThread(CoreProgressManager.java:613)
at com.intellij.openapi.progress.impl.CoreProgressManager.run(CoreProgressManager.java:410)
at com.redhat.devtools.lsp4ij.features.progress.LSPProgressManager.createTask(LSPProgressManager.java:86)
at com.redhat.devtools.lsp4ij.features.progress.LSPProgressManager.notifyProgress(LSPProgressManager.java:210)
at com.redhat.devtools.lsp4ij.client.LanguageClientImpl.notifyProgress(LanguageClientImpl.java:433)
…
at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.handleNotification(RemoteEndpoint.java:225)
Meanwhile the highlighting passes wait in CompletableFutures.awaitWithCheckCanceled for semantic tokens, folding ranges, code lenses, inlay hints and document links.
Steps
- In a headless test with a heavy project fixture, define gopls 0.24.0 as a user-defined language server for
*.go, on a module with amain.go. - Open
main.goand calldoHighlighting().
Expected: the highlighting gets the answers of gopls, as it does with clangd or zls, which send no $/progress at start.
Actual: doHighlighting() never returns; the suite's hang watchdog reports it after 300 s. With notifyProgress overridden to do nothing in the language client, the same test passes in 7 s. rust-analyzer (212 $/progress notifications for a small Cargo project), jdtls (34) and typescript-language-server (2) send it too.
Where we saw it: checking semantic tokens with real language servers for #2338.
A possible fix: never run the task in the reading thread, for example by starting it from a pooled thread, or with ProgressManager.runProcessWithProgressAsynchronously, which runs it on a pooled thread also when headless.
Activity
fix: a language server that reports a progress no longer hangs in a h…