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

Are there any options for retrying file codesign logic when it fails due to a timestamp service unavailable issue on MacOS? #8089

Closed
appdevbuild opened this issue Mar 1, 2024 · 2 comments · Fixed by #8101

Comments

@appdevbuild
Copy link

  • Electron-Builder Version: 24.12.0
  • Node Version: 18.16.1
  • Electron Version: Any
  • Electron Type (current, beta, nightly): Any
Any
  • Target: x64 & arm64

We always encounter apple's timestamp service unavailable issues when we are building electron packages on macOS.
Error like this: The timestamp service is not available.

This error occurred randomly when it was signing files one by one. There are no network issues on AWS, actually.
But when this error occurs, we have to restart the whole building process, although the signing step only takes up a small portion of the total building time. This will waste a lot of time.

Are there any solutions to retry signing a file when it fails with a timestamp issue?

@appdevbuild appdevbuild changed the title Are there any solutions that codesign logic could retry when it has failed with timestamp service is not available on macos? Are there any options for retrying codesign logic when it fails due to a timestamp service unavailable issue on MacOS? Mar 1, 2024
@appdevbuild appdevbuild changed the title Are there any options for retrying codesign logic when it fails due to a timestamp service unavailable issue on MacOS? Are there any options for retrying file codesign logic when it fails due to a timestamp service unavailable issue on MacOS? Mar 1, 2024
@mmaietta
Copy link
Collaborator

mmaietta commented Mar 4, 2024

We use the official @electron/osx-sign npm package for signing. I'm not sure if we can wrap their exported function with a retry block, but feel free to give this patch-package a shot:
app-builder-lib+24.13.3.patch

diff --git a/node_modules/app-builder-lib/out/macPackager.js b/node_modules/app-builder-lib/out/macPackager.js
index d5acbdd..9676310 100644
--- a/node_modules/app-builder-lib/out/macPackager.js
+++ b/node_modules/app-builder-lib/out/macPackager.js
@@ -336,7 +336,7 @@ class MacPackager extends platformPackager_1.PlatformPackager {
             identity: identity || "none",
             provisioningProfile: provisioningProfile || "none",
         }, customSign ? "executing custom sign" : "signing");
-        return customSign ? Promise.resolve(customSign(opts, this)) : (0, osx_sign_1.signAsync)(opts);
+        return customSign ? Promise.resolve(customSign(opts, this)) : (0, builder_util_1.retry)(() => (0, osx_sign_1.signAsync)(opts), 3, 1000, 1000);
     }
     //noinspection JSMethodCanBeStatic
     async doFlat(appPath, outFile, identity, keychain) {

It gives 3 retries with both an interval and backoff of 1 second.

@beyondkmp
Copy link
Contributor

beyondkmp commented Mar 6, 2024

I haven't encountered similar issues on Windows, but I have experienced this signing failure issue on macOS. Looking at the code, the dosign process on Windows includes a retry mechanism. Therefore, we can implement the same method on macOS as well.

export async function doSign(configuration: CustomWindowsSignTaskConfiguration, packager: WinPackager) {
// https://github.com/electron-userland/electron-builder/pull/1944
const timeout = parseInt(process.env.SIGNTOOL_TIMEOUT as any, 10) || 10 * 60 * 1000
// decide runtime argument by cases
let args: Array<string>
let env = process.env
let vm: VmManager
const vmRequired = configuration.path.endsWith(".appx") || !("file" in configuration.cscInfo!) /* certificateSubjectName and other such options */
const isWin = process.platform === "win32" || vmRequired
const toolInfo = await getToolPath(isWin)
const tool = toolInfo.path
if (vmRequired) {
vm = await packager.vm.value
args = computeSignToolArgs(configuration, isWin, vm)
} else {
vm = new VmManager()
args = configuration.computeSignToolArgs(isWin)
if (toolInfo.env != null) {
env = toolInfo.env
}
}
try {
await vm.exec(tool, args, { timeout, env })
} catch (e: any) {
if (e.message.includes("The file is being used by another process") || e.message.includes("The specified timestamp server either could not be reached")) {
log.warn(`First attempt to code sign failed, another attempt will be made in 15 seconds: ${e.message}`)
await new Promise((resolve, reject) => {
setTimeout(() => {
vm.exec(tool, args, { timeout, env }).then(resolve).catch(reject)
}, 15000)
})
}
throw e
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants