Skip to content

Commit 89b6d85

Browse files
fix(scripts): bound android-release-signing exec operations (#110822)
* fix(scripts): bound android-release-signing exec operations * fix(scripts): test Android signing timeouts Co-authored-by: wanyongstar <[email protected]> * fix(scripts): keep signing timeout internal * docs(scripts): clarify signing timeout scope * test(agents): isolate transport timeout proof --------- Co-authored-by: Peter Steinberger <[email protected]>
1 parent a54e28e commit 89b6d85

4 files changed

Lines changed: 57 additions & 3 deletions

File tree

‎scripts/android-release-signing.mjs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env node
2-
import { execFileSync } from "node:child_process";
32
import fs from "node:fs";
43
import path from "node:path";
54
import process from "node:process";
65
import { fileURLToPath } from "node:url";
6+
import { runAndroidSigningCommandSync } from "./lib/android-release-signing-process.mjs";
77

88
const rootDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
99
const defaultManifestPath = path.join(rootDir, "apps", "android", "Config", "ReleaseSigning.json");
@@ -185,15 +185,15 @@ function requireMatchPassword() {
185185
}
186186

187187
function run(command, args, options = {}) {
188-
execFileSync(command, args, {
188+
runAndroidSigningCommandSync(command, args, {
189189
cwd: options.cwd,
190190
env: options.env || process.env,
191191
stdio: options.stdio || "pipe",
192192
});
193193
}
194194

195195
function runText(command, args, options = {}) {
196-
return execFileSync(command, args, {
196+
return runAndroidSigningCommandSync(command, args, {
197197
cwd: options.cwd,
198198
env: options.env || process.env,
199199
encoding: "utf8",
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export interface AndroidSigningCommandOptions {
2+
cwd?: string | URL;
3+
encoding?: BufferEncoding | "buffer" | null;
4+
env?: NodeJS.ProcessEnv;
5+
stdio?: unknown;
6+
timeoutMs?: number;
7+
}
8+
9+
export function runAndroidSigningCommandSync(
10+
command: string,
11+
args: readonly string[],
12+
options?: AndroidSigningCommandOptions,
13+
): Buffer | string | null;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { execFileSync } from "node:child_process";
2+
3+
// This helper bounds only Git and small OpenSSL calls from android-release-signing.mjs.
4+
// Gradle and Fastlane release builds use separate entrypoints and do not inherit this timeout.
5+
const ANDROID_SIGNING_TIMEOUT_MS = 120_000;
6+
7+
export function runAndroidSigningCommandSync(command, args, options = {}) {
8+
const timeoutMs = options.timeoutMs ?? ANDROID_SIGNING_TIMEOUT_MS;
9+
try {
10+
return execFileSync(command, args, {
11+
cwd: options.cwd,
12+
encoding: options.encoding,
13+
env: options.env,
14+
killSignal: "SIGKILL",
15+
stdio: options.stdio,
16+
timeout: timeoutMs,
17+
});
18+
} catch (error) {
19+
if (error && typeof error === "object" && error.code === "ETIMEDOUT") {
20+
throw new Error(
21+
`Android release signing command timed out after ${timeoutMs}ms: ${command}`,
22+
{ cause: error },
23+
);
24+
}
25+
throw error;
26+
}
27+
}

‎test/scripts/android-release-signing.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import fs from "node:fs";
44
import os from "node:os";
55
import path from "node:path";
66
import { afterEach, describe, expect, it } from "vitest";
7+
import { runAndroidSigningCommandSync } from "../../scripts/lib/android-release-signing-process.mjs";
78

89
const SCRIPT = path.join(process.cwd(), "scripts", "android-release-signing.mjs");
910
const MATCH_PASSWORD = "test-match-password";
@@ -133,6 +134,19 @@ afterEach(() => {
133134
});
134135

135136
describe("scripts/android-release-signing.mjs", () => {
137+
it("terminates a hung signing command at its deadline", () => {
138+
const timeoutMs = 100;
139+
const startedAt = Date.now();
140+
141+
expect(() =>
142+
runAndroidSigningCommandSync(process.execPath, ["-e", "setInterval(() => {}, 1_000)"], {
143+
stdio: "pipe",
144+
timeoutMs,
145+
}),
146+
).toThrow(`Android release signing command timed out after ${timeoutMs}ms`);
147+
expect(Date.now() - startedAt).toBeLessThan(5_000);
148+
});
149+
136150
it.each([
137151
["--mode"],
138152
["--mode", "--manifest"],

0 commit comments

Comments
 (0)