mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 19:53:50 +00:00
* fix(adb): classify adb launch failures through the shared launch owner The adb version probe and device commands read a launcher error with the refusal-only table plus their own capacity check, so E2BIG became an adb protocol failure and host capacity at the version probe became an "unavailable" configuration. Both now read the launcher's failure with launcherFailureOf and report host capacity and oversized launches through classifyLaunchFailure; the selected-binary refusals keep adb's own configuration reports. The adb-specific capacity error, its remediation, the host_capacity configuration code and the exported refusal-code helper are removed. Refs #11614 * docs(adb): describe adb launch constraints as shared resource errors
112 lines
3.6 KiB
TypeScript
112 lines
3.6 KiB
TypeScript
import { execFile } from "node:child_process";
|
|
import { chmod, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { promisify } from "node:util";
|
|
import { expect, it } from "vitest";
|
|
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
|
|
// Exhausts the open-file limit, then starts the selected adb through the
|
|
// version probe and a device command; both take the owned stop-signal route.
|
|
const PRESSURE = `
|
|
import { open } from "node:fs/promises";
|
|
import { pathToFileURL } from "node:url";
|
|
const [repo, binary] = process.argv.slice(1);
|
|
const load = (path) => import(pathToFileURL(repo + "/dist/" + path));
|
|
const { inspectAdbClient } = await load("adb/AdbConfiguration.js");
|
|
const { runAdbCapture } = await load("adb/AdbCommand.js");
|
|
const selection = { binary, pathSource: "environment", environment: {} };
|
|
const probe = () =>
|
|
inspectAdbClient(selection).then(
|
|
(identity) => ({ version: identity.version }),
|
|
(cause) => ({
|
|
tag: cause._tag,
|
|
resource: cause.resource,
|
|
retryable: cause.retryable,
|
|
reportedLimits: cause.reportedLimits,
|
|
}),
|
|
);
|
|
const command = () =>
|
|
runAdbCapture("adb devices", { device: "serial" }, selection, ["devices"],
|
|
{ timeoutMs: 10_000, maxOutputBytes: 1024 }, undefined,
|
|
).then((result) => result.ok ? { ok: true } : {
|
|
tag: result.error._tag,
|
|
resource: result.error.resource,
|
|
retryable: result.error.retryable,
|
|
reportedLimits: result.error.reportedLimits,
|
|
});
|
|
const handles = [];
|
|
for (let index = 0; index < 128; index += 1) {
|
|
try {
|
|
handles.push(await open("/dev/null", "r"));
|
|
} catch (cause) {
|
|
if (cause.code !== "EMFILE") throw cause;
|
|
break;
|
|
}
|
|
}
|
|
if (handles.length === 128) throw new Error("Run under a low descriptor limit");
|
|
const pressure = { probe: await probe(), command: await command() };
|
|
for (const handle of handles) await handle.close();
|
|
const after = { probe: await probe(), command: await command() };
|
|
process.stdout.write(JSON.stringify({ pressure, after }));
|
|
`;
|
|
|
|
it.skipIf(process.platform === "win32")(
|
|
"reports open-file exhaustion as retryable host capacity without an unhandled spawn error",
|
|
async () => {
|
|
const directory = await createTestTempDirectory("rea-adb-descriptors-");
|
|
const adb = join(directory, "adb");
|
|
await writeFile(
|
|
adb,
|
|
`#!/bin/sh
|
|
if [ "$1" = version ]; then printf 'Android Debug Bridge version 1.0.41\\nVersion 34.0.5-cli\\n'; fi
|
|
exit 0
|
|
`,
|
|
);
|
|
await chmod(adb, 0o755);
|
|
const { stdout, stderr } = await promisify(execFile)(
|
|
"/bin/sh",
|
|
[
|
|
"-c",
|
|
'ulimit -n 64; exec "$@"',
|
|
"adb-descriptor-pressure",
|
|
process.execPath,
|
|
"--input-type=module",
|
|
"--eval",
|
|
PRESSURE,
|
|
process.cwd(),
|
|
adb,
|
|
],
|
|
{ timeout: 30_000, maxBuffer: 1024 * 1024 },
|
|
);
|
|
|
|
// An unhandled child error would exit the process before this report.
|
|
expect(stderr).toBe("");
|
|
expect(JSON.parse(stdout)).toEqual({
|
|
pressure: {
|
|
probe: {
|
|
tag: "AnalysisResourceConstraintError",
|
|
resource: "capacity",
|
|
retryable: true,
|
|
reportedLimits: {
|
|
spawn_error: "EMFILE",
|
|
exhausted_resource: "file-descriptors",
|
|
command: adb,
|
|
},
|
|
},
|
|
command: {
|
|
tag: "AnalysisResourceConstraintError",
|
|
resource: "capacity",
|
|
retryable: true,
|
|
reportedLimits: {
|
|
spawn_error: "EMFILE",
|
|
exhausted_resource: "file-descriptors",
|
|
command: adb,
|
|
},
|
|
},
|
|
},
|
|
after: { probe: { version: "34.0.5-cli" }, command: { ok: true } },
|
|
});
|
|
},
|
|
);
|