Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow manually killing the server process #834

Closed
bostick opened this issue Oct 15, 2021 · 7 comments
Closed

Allow manually killing the server process #834

bostick opened this issue Oct 15, 2021 · 7 comments

Comments

@bostick
Copy link

bostick commented Oct 15, 2021

I am developing an LSP client extension.

Let's say that I had a typo in my command of the ServerOptions object that I'm creating.

The command is now some command that hangs when given the usual traffic from an LSP client.

I am already showing an error message after 10 seconds if this happens.

I am interested in also manually killing the server process that was started.

I could not see if there was already an API for doing that, so I am creating this issue.

This is not anything to do with the actual protocol, because I am talking about a process that does not even understand the protocol.

This is low-level error handling and cleanup.

The real-world case that I am trying to solve is running a command that may not have the proper packages installed yet, and so hangs on startup.

@dbaeumer
Copy link
Member

You can simply call stop() on the client. That kills / stops the server.

@bostick
Copy link
Author

bostick commented Oct 18, 2021

I tried using stop, but the server process was not killed.

The server process that was started is still hanging after calling stop.

What is the mechanism by which stop kills the server?

If it is by sending a shutdown message via LSP, then that is not sufficient for my case, because the server may not be responsive.

I tried explaining the situation in this related issue for Sublime LSP:

sublimelsp/LSP#1872

@dbaeumer
Copy link
Member

It is killed using this piece of code:

But it sounds like the super stop call fails in our case. Can you check this?

@bostick
Copy link
Author

bostick commented Oct 19, 2021

I have not had success in the past with setting up debugging of my language server extension, but I will try it again.

@dbaeumer
Copy link
Member

OK. Let me know any outcome.

@bostick
Copy link
Author

bostick commented Oct 19, 2021

I believe that the super.stop() promise in LanguageClient.stop is never being resolved, and so e.g. checkProcessDied is never running.

This is the version of BaseLanguageClient.stop that I see when debugging:

stop() {
    this._initializeResult = undefined;
    if (!this._connectionPromise) {
        this.state = ClientState.Stopped;
        return Promise.resolve();
    }
    if (this.state === ClientState.Stopping && this._onStop) {
        return this._onStop;
    }
    this.state = ClientState.Stopping;
    this.cleanUp(false);
    // unhook listeners
    return this._onStop = this.resolveConnection().then(connection => {
        return connection.shutdown().then(() => {
            connection.exit();
            connection.end();
            connection.dispose();
            this.state = ClientState.Stopped;
            this.cleanUpChannel();
            this._onStop = undefined;
            this._connectionPromise = undefined;
            this._resolvedConnection = undefined;
        });
    });
}

When a functioning language server is setup, the connection.shutdown() promise IS resolved.

When a malfunctioning language server is setup, the connection.shutdown() promise is NOT resolved.

And this makes sense, because connection.shutdown() sends a request and never gets a response from a malfunctioning server.

caveat: this is all based on my reading, I may not be understanding the code, etc.

@dbaeumer
Copy link
Member

Added code that ensure that the server gets killed even if the shutdown times out / connection got closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants