Skip to content

Semantic tokens, document links and LSP intentions hold highlighting read actions while they wait for the language server #2017

Open

Description

@lagergren

Three freezes of LSP4IJ 0.21.0 in #2014, all at startup with probable cause LONG_READ_ACTION and the IDE killed, have highlighting threads waiting for a language server while they hold the read lock, while the EDT waits for the write lock:

Report IDE Freeze Waiting in
2116064504671633408 IntelliJ IDEA 262.10968.63 44 s LSPSemanticTokensHighlightVisitor.getSemanticTokens (line 203), and four more threads in LSPDocumentLinkCollector.collect (line 79)
2108943541375074304 RustRover 262.10968.75 41 s LSPDocumentLinkCollector.collect (line 79)
2116205187730509824 IntelliJ IDEA 262.10968.63 44 s LSPIntentionCodeActionSupport.getCodeActionAt (line 154), from LSPLazyCodeActionIntentionAction.getFamilyName in ShowIntentionsPass

Each waits in ProgressIndicatorUtils.awaitWithCheckCanceled, inside a tryRunReadAction of the highlighting. The code relies on a write action cancelling the pass's progress, so that awaitWithCheckCanceled throws and the read lock is released, as the comments of LSPSemanticTokensHighlightVisitor.getSemanticTokens and LSPIntentionCodeActionSupport.getCodeActionAt say. In these reports that didn't happen for 40 s or more. awaitWithCheckCanceled checks the progress every few milliseconds, so the progress wasn't cancelled.

In 0.30.0: unchanged. The three waits are still there (lines 203 and 79, and line 170 in getCodeActionAt); 2a5d042 only made them null-safe. #1871 stopped the EDT from waiting for intention code actions, but ShowIntentionsPass still waits in its read action. I haven't reproduced the freezes on 0.30.0 yet.

Possible fix: don't wait in the passes. Use the reply if it's there, and otherwise return and restart the highlighting when it arrives, as #1871 does on the EDT (refreshWhenLoaded) and as the document links already do after a cancellation (pendingFuture).

Activity

  1. lagergren commented on Nov 18, 2026

    @lagergren
    CollaboratorAuthor

    Not reproduced on main (0bdec3f, 0.30.0), in IntelliJ IDEA 2026.3 (IU-263.7307.200) or 2026.2.4 (IU-262.11879.100).

    With a language server that answers textDocument/semanticTokens/full, textDocument/documentLink or textDocument/codeAction after 15 s, I opened a file, waited until the server had the request, and 1.5 s later asked for a write action, from a VFS refresh or on the UI thread. Each time the write action waited 2 to 34 ms (1 to 74 ms without a slow request): the highlighting pass was cancelled and released the read lock, as the code expects.

    So a slow server alone doesn't cause these freezes in these IDE versions. The reports came from older 2026.2 builds (262.8665, 262.10968), all at startup, and what kept the passes from being cancelled there is still unknown. I'm keeping this open as not reproducible, to compare with freeze reports of 0.30.0, which have a com.redhat.devtools.lsp4ij.internal.CompletableFutures.awaitWithCheckCanceled frame above ProgressIndicatorUtils.awaitWithCheckCanceled.

  2. lagergren commented on Nov 18, 2026

    @lagergren
    CollaboratorAuthor

    A closer look at the three reports: in all of them, the UI thread wasn't waiting for a write action, but for a write-intent permit (NestedLocksThreadingSupport.acquireWriteIntentPermit, under SuvorovProgress), which another thread's read action doesn't block by itself. So most likely a third thread was waiting to write, and the UI thread was queued behind it; the reports don't include that thread. All three happened at startup, where a VFS refresh writes on a background thread, as in the report of the description of #2014. That would also explain why the highlighting passes weren't cancelled in these 2026.2 builds (262.10968.63, 262.10968.75), while 2026.2.4 (262.11879.100) and 2026.3 cancel them for a write action on a background thread in my reproduction. It also means that the approach of #2019, which gives way when the UI thread waits for a write action, wouldn't have helped here.

    A fix that doesn't rely on the IDE cancelling the passes would make them never wait for the language server: use the reply if it's there, and run the highlighting again when it comes. That is a large change to code that runs all the time, which I'd rather base on a reproduction. So the plan is to compare with the freeze reports of 0.30.0, which have a com.redhat.devtools.lsp4ij.internal.CompletableFutures.awaitWithCheckCanceled frame above ProgressIndicatorUtils.awaitWithCheckCanceled, and with the IDE builds they come from. If these stacks come back on current builds, their conditions should let us reproduce them, and the change is worth making; if they don't, this can be closed as fixed in the IDE.

    @angelozerr, once 0.30.0 is out, could you post here the freeze reports with these stacks, with their IDE builds?

  3. lagergren commented on Nov 18, 2026

    @lagergren
    CollaboratorAuthor

    Not reproduced either on the exact build of two of these reports, IntelliJ IDEA 2026.2.3 (IU-262.10968.63), with main (0.30.0). With a language server that answers textDocument/semanticTokens/full, textDocument/documentLink or textDocument/codeAction after 15 s, a write action asked for 1.5 s after the server had the request waited 10 to 19 ms when it came from a VFS refresh on a background thread, and 9 to 12 ms when it ran on the UI thread (52 and 2 ms without a slow request), and IntelliJ recorded no freeze. So the build isn't what made these passes wait: the freezes needed something more than a slow server and a write action, most likely something of the startup at which all of them happened, or of the other plugins and language servers running then. The plan above stands: the freeze reports of 0.30.0, with what else ran at the time, are what can tell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions