Skip to content

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

Closed

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?

Activity

  1. dbaeumer commented on Jan 11, 2021

    @dbaeumer
    Member

    There are two things:

    • VS Code crashes / gets killed: servers need to protect themselves against this. This is why VS Code adds the process id of the process starting the server to the command line. It is also send in the initialize request. That allows a server to monitor the editor process and if it disappears exit gracefully.
    • the other behavior sounds like a bug.
  2. added
    bug
    on Jan 11, 2021
  3. added this to the milestone on Jan 11, 2021
  4. dsherret commented on Jun 22, 2021

    @dsherret
    Contributor

    We've noticed this behaviour as well and it leads to orphaned processes. The problem is that the code queues up an exit notification to send, but then closes the connection before the notification is actually sent. I've opened #776 to fix this issue.

  5. bpringe commented on Jun 23, 2021

    @bpringe
    Author

    Thanks for the fix!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions