-
Notifications
You must be signed in to change notification settings - Fork 370
Open
Labels
bugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bug
Milestone
Description
We are working on an LS for Odoo, and we have encountered an error that happens due to change in state.
Let me describe the scenario:
- We have a listener on
onDidChangeConfigurationthat based on some condition closes the client withawait client.stop(15000). - In the Client base code you also have a listener to
sendNotificationwith thedidChangeConfigurationNotification to be sent to the server. - Since we stop the client the state is updated, but it is updated after the check you have at the top of the function Here:
vscode-languageserver-node/client/src/common/client.ts
Lines 984 to 987 in d810d51
public async sendNotification<P>(type: string | MessageSignature, params?: P): Promise<void> { if (this.$state === ClientState.StartFailed || this.$state === ClientState.Stopping || this.$state === ClientState.Stopped) { return Promise.reject(new ResponseError(ErrorCodes.ConnectionInactive, `Client is not running`)); } - At that point the state is still running, so it goes forward until it calls
$starthere:vscode-languageserver-node/client/src/common/client.ts
Lines 999 to 1000 in d810d51
// Ensure we have a connection before we force the document sync. const connection = await this.$start(); - Then while it awaits
this.start()which is probably already a resolved promise, the code is interrupted, and the stop function is called, so the state changes tostopping.
vscode-languageserver-node/client/src/common/client.ts
Lines 1755 to 1765 in d810d51
private async $start(): Promise<Connection> { if (this.$state === ClientState.StartFailed) { throw new Error(`Previous start failed. Can't restart server.`); } await this.start(); const connection = this.activeConnection(); if (connection === undefined) { throw new Error(`Starting server failed`); } return connection; } - Then of course when it goes to
this.activeConnection()it returns undefined, which then throws an error.
vscode-languageserver-node/client/src/common/client.ts
Lines 1232 to 1234 in d810d51
private activeConnection(): Connection | undefined { return this.$state === ClientState.Running && this._connection !== undefined ? this._connection : undefined; } - However in this case from our POV, it is not an error, because it was trying to send a notification while the server is stopping, and the state was stopping/stopped. I think maybe there should be a guard to check the state before raising the error so that the state is up to date.
Metadata
Metadata
Assignees
Labels
bugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bug