Skip to content

Commit

Permalink
fix: windows sometimes failing on EPERM in download
Browse files Browse the repository at this point in the history
Adding a retry should fix #233
  • Loading branch information
connor4312 committed Oct 4, 2023
1 parent 453dba5 commit 3558f3b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### 2.3.5 | 2022-10-04

- Fix windows sometimes failing on EPERM in download

### 2.3.4 | 2022-07-31

- Fix "insiders" string not matching correctly
Expand Down
16 changes: 15 additions & 1 deletion lib/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
streamToBuffer,
systemDefaultPlatform,
} from './util';
import * as timers from 'timers/promises';

const extensionRoot = process.cwd();
const pipelineAsync = promisify(pipeline);
Expand Down Expand Up @@ -422,7 +423,20 @@ export async function download(options: Partial<DownloadOptions> = {}): Promise<
// important! do not put anything async here, since unzipVSCode will need
// to start consuming the stream immediately.
await unzipVSCode(reporter, downloadStaging, stream, platform, format);
await fs.promises.rename(downloadStaging, downloadedPath);

// Windows file handles can get released asynchronously, give it a few retries:
for (let attempts = 20; attempts >= 0; attempts--) {
try {
await fs.promises.rename(downloadStaging, downloadedPath);
break;
} catch (e) {
if (attempts === 0) {
throw e;
} else {
await timers.setTimeout(200);
}
}
}

reporter.report({ stage: ProgressReportStage.NewInstallComplete, downloadedPath });
break;
Expand Down

0 comments on commit 3558f3b

Please sign in to comment.