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: Rename the old server before update #9585
Conversation
94bda12
to
75b0892
Compare
r? @wxb1ank |
editors/code/src/net.ts
Outdated
const entries = await vscode.workspace.fs.readDirectory(serverDir); | ||
for (const [entry, _] of entries) { | ||
try { | ||
const parsedPath = path.parse(entry); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what entry
is here.
75b0892
to
5280b6d
Compare
Sorry if I'm missing something, but how is temporarily renaming the server to 'stale' different than replacing it with the newly downloaded one? I haven't tested, but if one or more server instances are running, won't this always cause EPERM? |
It seems that you actually can rename a running executable on Windows. But yeah, this is untested otherwise. |
I feel like we wouldn't have run into the original permission error if that were the case. IMO, the simplest thing to do here is to check specifically for EPERM and log something ala "Failed to overwrite the old server executable. Are there instances currently running?". Needing to update RA while it's running seems like a niche case to me. |
Yeah, I'd agree, but this seems to bother a lot of people. So while it's not a full solution, at least it might take us 90% of the way there. |
Well, the code LGTM otherwise. The first Google result I found on this topic implied this couldn't be done, but this suggests otherwise? I'll try and test this later today or tomorrow. |
I tested with two VS Code windows open. One was running RA in the background while the other attempted to update.
https://github.com/rust-analyzer/rust-analyzer/blob/5280b6d84c4fc727d055b02239d631963264cb2b/editors/code/src/net.ts#L127
|
With the following: // Try to rename a running server to avoid EPERM on Windows
// NB: this can lead to issues if a running Code instance tries to restart the server.
try {
await vscode.workspace.fs.rename(opts.dest, oldServerPath, { overwrite: true });
log.info(`Renamed old server binary ${opts.dest.fsPath} to ${oldServerPath.fsPath}`);
} catch (err) {
}
try {
await vscode.workspace.fs.rename(tempFilePath, opts.dest, { overwrite: true });
} catch (err) {
log.error(`Failed to replace the old binary with the new one: ${err}`);
} I no longer receive the previous error, and the update seems to go smoothly (with the old RA instance still active). |
5280b6d
to
cfaf186
Compare
I ended up checking for both, to avoid showing an error when there's no existing binary, but still complain when something happens. Of course Also, thanks a lot for giving this a try! |
I think I want to merge this today so we can test it a little before next week (unless someone r-'es it, of course). |
bors r+ |
Kinda' fixes #6602