fix(language-server): wait for cancellation before re-acquiring lint worker#677
Open
MyWWWChat wants to merge 1 commit into
Open
fix(language-server): wait for cancellation before re-acquiring lint worker#677MyWWWChat wants to merge 1 commit into
MyWWWChat wants to merge 1 commit into
Conversation
…worker Three correlated issues caused diagnostics to silently disappear after the first textDocument/didChange: 1. `void lastSemanticJob.cancel()` is fire-and-forget; the next `await pool.proxy()` may hand back the same worker that's mid-termination, and the call rejects with "Worker is terminated". 2. `workerTerminateTimeout: 0` removes any drain period, so (1) hits on every cancellation cycle. Workerpool's own default is 1000ms. 3. The catch block treats the transient termination error as fatal noise — `console.error` and no retry — so users see `publishDiagnostics: []` instead of any actual lint result. Fix: - Await the in-flight cancellation (try/catch swallows the expected CancellationError). - Restore a 1s grace period on worker termination. - Retry the lint once when the underlying error matches /worker is terminated/i; let CancellationError propagate untouched. Reproducer (LSP harness): a didOpen followed by a didChange ~3s later returns `[]` for syntactically-broken text on every release tested (2.0.0-next.6 … 2.0.0-next.32). After the patch, the syntax error is delivered as expected on every change.
|
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.
Summary
Three stacked issues in
packages/language-server/src/linting.tscausepublishDiagnostics: []after the firsttextDocument/didChange. After this fix the lint pipeline survives rapid document changes and delivers diagnostics on every turn.The bug
cancel()is not awaited; the nextpool.proxy()may return the same worker mid-termination.workerTerminateTimeout: 0removes any drain period, so (1) hits on every cancellation cycle. Workerpool's own default is1e3ms.Worker is terminatedrejection is treated as fatal noise —console.errorand no retry — so the user-visible result is empty diagnostics.Reproduction
LSP harness against a freshly installed
@neo4j-cypher/language-server(works on every release tested,2.0.0-next.6…2.0.0-next.32):Stderr fires
Error: Worker is terminatedon the second turn;publishDiagnosticsfor the syntactically-broken text comes back as[]instead of containing the parser error.Fix
Three correlated changes — none of them by themselves is enough on every Node version / load profile we hit, but together they make the pipeline robust:
lastSemanticJob.cancel(); try { await lastSemanticJob; } catch { /* CancellationError */ }. Wait for the resource to actually be released before re-acquiring it (classical producer-consumer-with-graceful-cancellation idiom; mapped to Node's promise model it's justawaiting the rejection).workerTerminateTimeout: 0→1000in bothpool()calls. Restores a non-zero grace period for worker drain. Matches workerpool's own default./worker is terminated/ias belt-and-braces for any residual race the first two changes don't cover.CancellationErroris re-thrown unchanged so cancellation semantics remain identical.Test plan
[{ severity: 1, message: 'Expected...' }]on the second turn (was[]).didOpen).CancellationErrorstill propagates out of the try block — no behavior change for legitimate cancellation paths.pnpm testinpackages/language-server(local environment lacked the full ANTLR toolchain — please verify on CI).Notes
While digging through this I also noticed that in
2.0.0-next.32rawLintDocumentreadsresult.diagnosticsandresult.symbolTables, but the bundledlintCypherQueryreturns a bare array. Same user-visible symptom (empty diagnostics) by a different path. That looks like a separate refactor left half-finished and is not addressed in this PR — flagging in case it's news.