microsoft / microsoft/vscode-languageserver-node
LanguageClient.sendNotification fails due to change in state due to stopping client.
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.8k
- Forks
- 404
- Avg merge
- 2d 8h
- Merged PRs (30d)
- 14
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: https://github.com/microsoft/vscode-languageserver-node/blob/d810d51297c667bd3a3f46912eb849055beb8b6b/client/src/common/client.ts#L984-L987
- At that point the state is still running, so it goes forward until it calls
$starthere: https://github.com/microsoft/vscode-languageserver-node/blob/d810d51297c667bd3a3f46912eb849055beb8b6b/client/src/common/client.ts#L999-L1000 - 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.
https://github.com/microsoft/vscode-languageserver-node/blob/d810d51297c667bd3a3f46912eb849055beb8b6b/client/src/common/client.ts#L1755-L1765 - Then of course when it goes to
this.activeConnection()it returns undefined, which then throws an error.
https://github.com/microsoft/vscode-languageserver-node/blob/d810d51297c667bd3a3f46912eb849055beb8b6b/client/src/common/client.ts#L1232-L1234 - 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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in client/src/common/client.ts at sendNotification, $start, start(), and activeConnection(), following the state transitions during concurrent notification and stop calls. Reproduce the Odoo language-server scenario and inspect existing client tests, if present; done means stopping or stopped clients no longer raise this notification error while normal sends still work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100