Skip to content

attempt to fix a race where new LS starts before previous LS stopped. #19076

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

Merged
merged 1 commit into from
May 10, 2022

Conversation

heejaechang
Copy link

@heejaechang heejaechang commented May 5, 2022

From crash report, we found a possible race situation where new Pylance is started before old Pylance is disposed causing duplicate commands to be registered and error out by LSP client.

this is an attempt to fix the race by making sure LSP server stop is awaited before calling start eliminating all weird cases and we no longer assume that languge client will be reused (start/stop and start again).

@karthiknadig karthiknadig requested a review from kimadeline May 5, 2022 22:42
@karrtikr karrtikr assigned kimadeline and unassigned karrtikr May 5, 2022
@heejaechang heejaechang added no-changelog No news entry required skip tests Updates to tests unnecessary labels May 5, 2022
@heejaechang heejaechang marked this pull request as draft May 6, 2022 08:38
@heejaechang
Copy link
Author

by the way, does anyone know when settings.json is changed, which code path in core extension call onDidChangeConfiguration on us?

Copy link

@kimadeline kimadeline left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which code path in core extension call onDidChangeConfiguration on us?

What do you mean? Who fires the onDidChangeConfiguration event?

@heejaechang
Copy link
Author

What do you mean? Who fires the onDidChangeConfiguration event?

figured out, it was LSP client itself raising the event. by the way, found issue on LSP itself as well
microsoft/vscode-languageserver-node#929

@heejaechang
Copy link
Author

heejaechang commented May 6, 2022

alright, it looks like whatever fix I made here in proxy won't fix the race. it turns out unlike before (< 2022.4.x), now, when interpreter is changed, completely new language server is created (sorry, I just found out once I couldn't figure out how the state change it is having happened). so, race can't be fixed in proxy, but must be fixed in
https://github.com/microsoft/vscode-python/blob/main/src/client/languageServer/watcher.ts#L137 where it stops and create new LS. (and probably other places, I saw multiple code paths that end up restart server)

it looks like the change happened in this PR (#18884)

any objection on just adding stop: Promise or make dispose async on proxy and all callers to make it simple and remove any chance of race?

tagging @kimadeline @karrtikr

@kimadeline
Copy link

any objection on just adding stop: Promise or make dispose async on proxy and all callers to make it simple and remove any chance of race?

I vote for the first option, not so sure about making dispose async for everything.

@heejaechang heejaechang changed the base branch from main to release-2022.6 May 6, 2022 23:52
@heejaechang
Copy link
Author

do you guys use cancellation? I don't see code path involved here use any cancellation. for example, if someone flip thorough different version of interpreters, in current form, every selection must start server and stop them one by one. rather than all the intermediate one gets cancelled if server is not started yet and only last selection start server?

@heejaechang heejaechang marked this pull request as ready for review May 9, 2022 18:04
@heejaechang
Copy link
Author

@kimadeline can you take a look?

@kimadeline
Copy link

Nope, we don't use cancellation, although it would make sense to use it. Do you think that would be a big change to the current code?

@kimadeline
Copy link

Also, there will be merge conflicts depending on which PR gets merged in first between this one and #19087.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog No news entry required skip tests Updates to tests unnecessary
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants