Skip to content

Orphaned server processes when VS Code client process is killed #726

@bpringe

Description

@bpringe

I've been trying to figure this out for a while, and I'm running out of ideas. I've read through this related thread: microsoft/vscode#35196

When I start the server from the client, I use a withProgress to monitor the progress. If close the VS Code client window right after the client start process begins, before client.onReady() returns, the server process is left orphaned/running.

    vscode.window.withProgress({
        location: vscode.ProgressLocation.Notification,
        title: "my title",
        cancellable: false
    }, (_progress, _token) => {
        return client.onReady();
    });
    client.start();

My extension's deactivate function looks like this:

function deactivate(): Promise<void> | undefined {
    // ... other unrelated cleanup code
    if (lspClient) {
        return lspClient.stop();
    }
}

I've also made sure not to add the returned disposable from client.start() to the extension context subscriptions as noted in the linked thread.

If I wait for the client to fully start, then close the VS Code window, the server is shutdown fine. The problem is only when VS Code is closed right after the server begins to start. I see in the server logs that shutdown is called in this case, but exit is never called. It seems the VS Code client process is terminated before the response from shutdown is received, therefore exit is never called.

The server's shutdown method isn't doing anything time-consuming. My only other suspicion is that the server's startup functionality causes the incoming shutdown request's processing to be delayed, so while shutdown doesn't take long to return, it may be a while before it's called. I have no proof of this though, just a guess.

Is there anything else I can try from the client's perspective?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue identified by VS Code Team member as probable bug

    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