From 3558f3b99d0b826faf6304f87dfe5236fbfc8417 Mon Sep 17 00:00:00 2001 From: Connor Peet Date: Wed, 4 Oct 2023 10:43:26 -0700 Subject: [PATCH 1/2] fix: windows sometimes failing on EPERM in download Adding a retry should fix #233 --- CHANGELOG.md | 4 ++++ lib/download.ts | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d947658..87ab5036 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/download.ts b/lib/download.ts index 888bff5e..08afb0ef 100644 --- a/lib/download.ts +++ b/lib/download.ts @@ -27,6 +27,7 @@ import { streamToBuffer, systemDefaultPlatform, } from './util'; +import * as timers from 'timers/promises'; const extensionRoot = process.cwd(); const pipelineAsync = promisify(pipeline); @@ -422,7 +423,20 @@ export async function download(options: Partial = {}): 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; From 623087105f08c0cfa3c7db927da16844e5e809db Mon Sep 17 00:00:00 2001 From: Connor Peet Date: Wed, 4 Oct 2023 10:43:52 -0700 Subject: [PATCH 2/2] 2.3.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ba6418e6..d7da8fbe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@vscode/test-electron", - "version": "2.3.4", + "version": "2.3.5", "scripts": { "compile": "tsc -p ./", "watch": "tsc -w -p ./",