Skip to content

onDidChangeConfiguration calls forEach(validateTextDocument) without awaiting; rejections terminate server #320

@morphqdd

Description

@morphqdd

What happens

In src/server.ts, the configuration-change handler revalidates every open document but discards every returned promise:

documents.all().forEach(validateTextDocument);

validateTextDocument is async (line 163). Array#forEach ignores return values, so each invocation's promise is dropped on the floor. If validation of any open document rejects — getDocumentSettings transport error, sendDiagnostics failure, parser exception — the rejection becomes an unhandledRejection on Node, which under Node 18+ default --unhandled-rejections=throw terminates the server process.

Same defect family as the document-change handler at lines 213-215, but multiplied across every open document on every configuration change.

What should happen

Wrap the calls in Promise.allSettled so every validation runs to completion and every rejection is caught individually:

Promise.allSettled(
    documents.all().map(doc =>
        validateTextDocument(doc).catch(err =>
            connection.console.error(`Validation failed for ${doc.uri}: ${err}`)
        )
    )
);

Result: a configuration change that triggers one bad document no longer kills the LSP server, and individual validation failures surface as log entries.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions