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

Automatic downloading language server with multiple VS Code windows open causes failure #3090

Closed
ninjasource opened this issue Feb 10, 2020 · 10 comments · Fixed by #3092
Closed

Comments

@ninjasource
Copy link

ninjasource commented Feb 10, 2020

Hi,

Great extension, thanks! I've just been through the install process (adding the extension - not building from source) and, unfortunately, I had multiple VS Code windows open at the same time. This caused the language server not to download properly on some of the VS Code windows. I don't know if the language server is scoped to the project or the entire VS Code installation. If the latter is the case then I guess there should be some sort of global mutex to protect the installation.

Windows 10, VS Code v1.42

David

@bjorn3
Copy link
Member

bjorn3 commented Feb 10, 2020

It is scoped to the vscode installation.

@deltaphc
Copy link

This might potentially be related to #3087.

@Veetaha
Copy link
Contributor

Veetaha commented Feb 10, 2020

I am investigating this, unfortunately, no fruits, I just have a supposition that this has something to do with antivirus protection...

@lnicola
Copy link
Member

lnicola commented Feb 10, 2020

I can't comment on #3087, but can you keep Process Monitor running when you run into this issue? It has options to log file system access and process creation.

I assume the language server is running. Could it be a race condition?

@lnicola
Copy link
Member

lnicola commented Feb 10, 2020

@Veetaha I can't check right now, are you downloading the binary to the final file? We could try to work around this by saving it to a temporary file, then renaming it with a number of retries just in case. But Procmon might still show something.

@Veetaha
Copy link
Contributor

Veetaha commented Feb 10, 2020

@lnicola I think i've managed to reproduce this with the following:

const fetch = require("node-fetch");
const path = require("path");
const fs = require("fs");
const { spawnSync } = require("child_process");

const file = path.resolve("ra_lsp_server.exe");

async function downloadFile(url, destFilePath) {
    const response = await fetch(url);

    return new Promise((resolve, reject) => response.body
        .on("end", resolve)
        .on("error", reject)
        .pipe(fs.createWriteStream(destFilePath))
    );
}

downloadFile(
    "https://github.com/rust-analyzer/rust-analyzer/releases/download/2020-02-10/ra_lsp_server-windows.exe", 
    file
).then(() => {
    const res = spawnSync(file, ["--version"]);
    console.dir(res);
    if (res.error) {
        console.error(res.error);
    }
})

@Veetaha
Copy link
Contributor

Veetaha commented Feb 10, 2020

I have a supposition that write-stream is not closed when the promise is resolved ...

@Veetaha
Copy link
Contributor

Veetaha commented Feb 10, 2020

Yes, I am 90% sure this is the problem!

@ninjasource
Copy link
Author

@Veetaha, I have Windows Defender as my anti virus if that helps. I think this may be caused by multiple VS Code instances automatically downloading and installing the same language server at the same time into the same location as @bjorn3 indicated that it was scoped to the vc code installation itself. I installed the extension on one of the open VS Code windows and all 3 running vs code windows then downloaded the language server at the same time. One of them "won" and thankfully I do not have a corrupted installation.

@Veetaha
Copy link
Contributor

Veetaha commented Feb 11, 2020

@ninjasource , thank you for the bug report. It is very valuable for us. If you downloaded the binary only from one vscode window, other windows should not change the day and there are no problems with your binary after you reload vscode. We already found the cause of the bug, and applied the fix in #3092

@bors bors bot closed this as completed in af9a9ab Feb 11, 2020
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

Successfully merging a pull request may close this issue.

5 participants