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

fix(mac): Wrap hditutil detach in retry w/ backoff #7600

Merged
merged 2 commits into from
Jun 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/large-items-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"builder-util": patch
"dmg-builder": patch
---

fix(mac): wrap hdiutil detach in retry w/ backoff
6 changes: 3 additions & 3 deletions packages/builder-util/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,14 +396,14 @@ export function executeAppBuilder(
}
}

export async function retry<T>(task: () => Promise<T>, retriesLeft: number, interval: number): Promise<T> {
export async function retry<T>(task: () => Promise<T>, retriesLeft: number, interval: number, backoff = 0, attempt = 0): Promise<T> {
try {
return await task()
} catch (error: any) {
log.info(`Above command failed, retrying ${retriesLeft} more times`)
if (retriesLeft > 0) {
await new Promise(resolve => setTimeout(resolve, interval))
return await retry(task, retriesLeft - 1, interval)
await new Promise(resolve => setTimeout(resolve, interval + backoff * attempt))
return await retry(task, retriesLeft - 1, interval, backoff, attempt + 1)
} else {
throw error
}
Expand Down
8 changes: 2 additions & 6 deletions packages/dmg-builder/src/dmgUtil.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { exec } from "builder-util"
import { exec, retry } from "builder-util"
import { PlatformPackager } from "app-builder-lib"
import { executeFinally } from "builder-util/out/promise"
import * as path from "path"
Expand Down Expand Up @@ -37,11 +37,7 @@ export async function detach(name: string) {
try {
await exec("hdiutil", ["detach", "-quiet", name])
} catch (e: any) {
await new Promise((resolve, reject) => {
setTimeout(() => {
exec("hdiutil", ["detach", "-force", name]).then(resolve).catch(reject)
}, 1000)
})
await retry(() => exec("hdiutil", ["detach", "-force", name]), 5, 1000, 500)
}
}

Expand Down