Skip to content

Build your personal knowledge base with Trilium Notes

feat(electron-forge): introduce basic expotential back-off for signing

Elian Doran31d8287e1b37
diff --git a/apps/desktop/electron-forge/sign-windows.cjs b/apps/desktop/electron-forge/sign-windows.cjs
index ddcf354c44..54e852f36b 100644
--- a/apps/desktop/electron-forge/sign-windows.cjs
+++ b/apps/desktop/electron-forge/sign-windows.cjs
@@ -1,8 +1,8 @@
-const child_process = require("child_process");
+const child_process = require("child_proces");
const fs = require("fs");
const path = require("path");
-module.exports = function (filePath) {
+module.exports = async function (filePath) {
const { WINDOWS_SIGN_EXECUTABLE } = process.env;
if (!WINDOWS_SIGN_EXECUTABLE) {
@@ -13,18 +13,46 @@ module.exports = function (filePath) {
const outputDir = path.join(__dirname, "sign");
console.log("Output dir is ", path.resolve(outputDir));
if (!fs.existsSync(outputDir)) {
- fs.mkdirSync(outputDir);
+ fs.mkdirSync(outputDir);
}
const command = `${WINDOWS_SIGN_EXECUTABLE} --executable "${filePath}"`;
console.log(`[Sign] Running ${command}`);
- try {
- child_process.execSync(command);
- } catch (e) {
- console.warn(`[Sign] Unable to sign ${filePath} due to:\n${e.stdout.toString("utf-8")})}`)
- return;
+ let remainingTries = 10;
+ let sleepTime = 10_000;
+ while (remainingTries > 0) {
+ try {
+ child_process.execSync(command);
+ console.log(`[Sign] Signed ${filePath} successfully.`);
+ break;
+ } catch (e) {
+ const output = e.stdout.toString("utf-8");
+ console.warn(`[Sign] Unable to sign ${filePath} due to:\n${output}`);
+
+ // Check if the error is retryable.
+ if (!output.includes("http://timestamp.digicert.com")) {
+ console.warn("Cannot retry due to unknown error.");
+ process.exit(1);
+ }
+
+ console.info(`Waiting for ${sleepTime / 1000}s before retrying...`);
+ }
+
+ await sleep(sleepTime);
+ sleepTime *= 2;
+ remainingTries--;
}
- console.log(`[Sign] Signed ${filePath} successfully.`);
-}
\ No newline at end of file
+ if (remainingTries < 1) {
+ console.error("Failed to sign.");
+ process.exit(1);
+ }
+
+}
+
+function sleep(time_ms) {
+ return new Promise((resolve) => {
+ setTimeout(resolve, time_ms);
+ });
+}