Skip to content

Commit

Permalink
fix(mac): Workaround for hdiutil randomly failing (#5431) (#5464)
Browse files Browse the repository at this point in the history
* fix(mac): Workaround for hdiutil randomly failing (#5431)

For unknown reasons hdiutil fails randomly when trying to create the dmg in
the tmp location. This workaround simply retries until it works or throws
the latest error if it fails ten times.

* fix(mac): Exporting and using retry from builder-util

Instead of having a similar implementation in createStageDmg as
the already existing "retry" function in builder-util it is now
exported from that package and used to handle the rerun-on-failure
in createStageDmg.

Co-authored-by: Eric Isoniemi <[email protected]>
  • Loading branch information
chokladmal and eikindred authored Jan 15, 2021
1 parent 5203d7e commit 53270cf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/builder-util/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ export function executeAppBuilder(args: Array<string>, childProcessConsumer?: (c
}
}

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): Promise<T> {
try {
return await task()
}
Expand Down
11 changes: 8 additions & 3 deletions packages/dmg-builder/src/dmg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { findIdentity, isSignAllowed } from "app-builder-lib/out/codeSign/macCod
import MacPackager from "app-builder-lib/out/macPackager"
import { createBlockmap } from "app-builder-lib/out/targets/differentialUpdateInfoBuilder"
import { executeAppBuilderAsJson } from "app-builder-lib/out/util/appBuilder"
import { Arch, AsyncTaskManager, exec, getArchSuffix, InvalidConfigurationError, isEmptyOrSpaces, log, spawn } from "builder-util"
import { Arch, AsyncTaskManager, exec, getArchSuffix, InvalidConfigurationError, isEmptyOrSpaces, log, spawn, retry } from "builder-util"
import { CancellationToken } from "builder-util-runtime"
import { copyDir, copyFile, exists, statOrNull } from "builder-util/out/fs"
import { stat } from "fs-extra"
Expand Down Expand Up @@ -191,10 +191,15 @@ async function createStageDmg(tempDmg: string, appPath: string, volumeName: stri
"-anyowners", "-nospotlight",
"-format", "UDRW",
])
if (log.isDebugEnabled) {
imageArgs.push("-debug")
}
imageArgs.push("-fs", "HFS+", "-fsargs", "-c c=64,a=16,e=16")
imageArgs.push(tempDmg)
await spawn("hdiutil", imageArgs)
return tempDmg
// The reason for retrying up to ten times is that hdiutil create in some cases fail to unmount due to "resource busy".
// https://github.com/electron-userland/electron-builder/issues/5431
await retry(() => spawn("hdiutil", imageArgs), 5, 1000)
return tempDmg;
}

function addLogLevel(args: Array<string>): Array<string> {
Expand Down

0 comments on commit 53270cf

Please sign in to comment.