Skip to content

Commit 3558f3b

Browse files
committed
fix: windows sometimes failing on EPERM in download
Adding a retry should fix #233
1 parent 453dba5 commit 3558f3b

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
### 2.3.5 | 2022-10-04
4+
5+
- Fix windows sometimes failing on EPERM in download
6+
37
### 2.3.4 | 2022-07-31
48

59
- Fix "insiders" string not matching correctly

lib/download.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
streamToBuffer,
2828
systemDefaultPlatform,
2929
} from './util';
30+
import * as timers from 'timers/promises';
3031

3132
const extensionRoot = process.cwd();
3233
const pipelineAsync = promisify(pipeline);
@@ -422,7 +423,20 @@ export async function download(options: Partial<DownloadOptions> = {}): Promise<
422423
// important! do not put anything async here, since unzipVSCode will need
423424
// to start consuming the stream immediately.
424425
await unzipVSCode(reporter, downloadStaging, stream, platform, format);
425-
await fs.promises.rename(downloadStaging, downloadedPath);
426+
427+
// Windows file handles can get released asynchronously, give it a few retries:
428+
for (let attempts = 20; attempts >= 0; attempts--) {
429+
try {
430+
await fs.promises.rename(downloadStaging, downloadedPath);
431+
break;
432+
} catch (e) {
433+
if (attempts === 0) {
434+
throw e;
435+
} else {
436+
await timers.setTimeout(200);
437+
}
438+
}
439+
}
426440

427441
reporter.report({ stage: ProgressReportStage.NewInstallComplete, downloadedPath });
428442
break;

0 commit comments

Comments
 (0)