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

Fix 100% CPU caused due to FS watchers when using liveshare #20006

Merged
merged 9 commits into from
Oct 17, 2022

Conversation

rchiodo
Copy link

@rchiodo rchiodo commented Oct 13, 2022

Fixes #20005

Root cause is roots coming from liveshare. Liveshare gives a workspaceFolder of vsls:/.

@rchiodo rchiodo added the bug Issue identified by VS Code Team member as probable bug label Oct 13, 2022
@@ -179,7 +179,7 @@ function watchRoots(args: WatchRootsArgs): IDisposable {

function createWorkspaceLocator(ext: ExtensionState): WorkspaceLocators {
const locators = new WorkspaceLocators(watchRoots, [
(root: vscode.Uri) => [new WorkspaceVirtualEnvironmentLocator(root.fsPath), new PoetryLocator(root.fsPath)],
(root: vscode.Uri) => [new WorkspaceVirtualEnvironmentLocator(root), new PoetryLocator(root.fsPath)],

Choose a reason for hiding this comment

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

is PeotryLocator safe? if root happen to have pyproject.toml on guest live share box, it might start to execute some shell commands on the remote machine? feels like getRoots needs to be changed to Uri and any locator that assumes file:// need to deal with non local uri?

Copy link
Author

Choose a reason for hiding this comment

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

The WorkspaceEnvironmentLocator seems to be the only one that doesn't pass a file to the file watcher. All the others seem to pass an exact file to look for.

Copy link
Author

Choose a reason for hiding this comment

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

But yeah they should all use the uri. I didn't want to make that big of a change though. It ripples all over the place.

Copy link
Author

Choose a reason for hiding this comment

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

@karthiknadig thoughts? Should I switch them all to use a URI and check the scheme?

Copy link
Author

Choose a reason for hiding this comment

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

Oh wait I just realized what Heejae was suggesting. It doesn't look it the locator runs any code, but callers of this might.

Copy link
Member

Choose a reason for hiding this comment

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

@karrtikr Can you answer the question?

Copy link

@karrtikr karrtikr Oct 17, 2022

Choose a reason for hiding this comment

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

Discovering or watching for Python interpreters doesn't make sense in vsls:/, as it's a virtual workspace. So I think ideally discovery component should be disabled as a whole. The issue is that we're initializing FS watchers in the constructor itself: #20023.

For now try checking if it's a virtual workspace before activating the watchers here:

Changes to URI are then not needed. Add:

export async function isVirtualWorkspace(): Promise<boolean> {
    const service = internalServiceContainer.get<IWorkspaceService>(IWorkspaceService);
    return service.isVirtualWorkspace;
}

in externalDependencies.ts and import it here.

TylerLeonhardt
TylerLeonhardt previously approved these changes Oct 13, 2022
@karrtikr
Copy link

Plan to have a look tomorrow, marking as draft.

@karrtikr karrtikr marked this pull request as draft October 14, 2022 01:32
@@ -179,7 +179,7 @@ function watchRoots(args: WatchRootsArgs): IDisposable {

function createWorkspaceLocator(ext: ExtensionState): WorkspaceLocators {
const locators = new WorkspaceLocators(watchRoots, [
(root: vscode.Uri) => [new WorkspaceVirtualEnvironmentLocator(root.fsPath), new PoetryLocator(root.fsPath)],
(root: vscode.Uri) => [new WorkspaceVirtualEnvironmentLocator(root), new PoetryLocator(root.fsPath)],
Copy link

@karrtikr karrtikr Oct 17, 2022

Choose a reason for hiding this comment

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

Discovering or watching for Python interpreters doesn't make sense in vsls:/, as it's a virtual workspace. So I think ideally discovery component should be disabled as a whole. The issue is that we're initializing FS watchers in the constructor itself: #20023.

For now try checking if it's a virtual workspace before activating the watchers here:

Changes to URI are then not needed. Add:

export async function isVirtualWorkspace(): Promise<boolean> {
    const service = internalServiceContainer.get<IWorkspaceService>(IWorkspaceService);
    return service.isVirtualWorkspace;
}

in externalDependencies.ts and import it here.

@rchiodo rchiodo marked this pull request as ready for review October 17, 2022 16:51
@rchiodo rchiodo added the skip tests Updates to tests unnecessary label Oct 17, 2022
traceError(ex);
this.watchersReady?.reject(ex);
});
this.watchersReady.resolve();

Choose a reason for hiding this comment

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

This should be outside the if statement.

Copy link
Author

Choose a reason for hiding this comment

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

Oh yeah, duh.

Copy link
Author

Choose a reason for hiding this comment

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

I should test again. It might have been working just because the promise never resolved.

Copy link

@karrtikr karrtikr left a comment

Choose a reason for hiding this comment

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

Feel free to merge after testing is done.

@rchiodo rchiodo merged commit cbb76d1 into microsoft:main Oct 17, 2022
@karrtikr karrtikr changed the title Make sure to check for 'files' when creating file watchers Fix 100% CPU caused due to FS watchers when using liveshare Oct 17, 2022
wesm pushed a commit to posit-dev/positron that referenced this pull request Mar 28, 2024
…/vscode-python#20006)

Fixes microsoft/vscode-python#20005

Root cause is roots coming from liveshare. Liveshare gives a
workspaceFolder of `vsls:/`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug skip tests Updates to tests unnecessary
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Python extension consistenly uses 100% CPU in liveshare scenario
5 participants