mirror of
https://github.com/morluto/rea.git
synced 2026-12-05 19:51:20 -05:00
fix(reverse): distinguish host capacity exhaustion from command launch failures
This commit is contained in:
@@ -40,6 +40,7 @@ import type {
|
||||
import {
|
||||
execFileOutput,
|
||||
execFileOutputFailure,
|
||||
HOST_SPAWN_CAPACITY_CODES,
|
||||
} from "../../process/ExecFileOutput.js";
|
||||
import {
|
||||
OwnedCommandFailure,
|
||||
@@ -579,6 +580,35 @@ export class ReverseEngineeringService {
|
||||
},
|
||||
{ cause, ...ownedCleanupOptions(cause) },
|
||||
);
|
||||
if (
|
||||
earlyFailure === undefined &&
|
||||
typeof code === "string" &&
|
||||
HOST_SPAWN_CAPACITY_CODES.has(code)
|
||||
) {
|
||||
const provider =
|
||||
operation === "inspect_with_objdump" ? "objdump" : "rizin";
|
||||
const setting =
|
||||
operation === "inspect_with_objdump"
|
||||
? "REA_OBJDUMP_COMMAND"
|
||||
: "REA_RIZIN_COMMAND";
|
||||
earlyFailure = new AnalysisResourceConstraintError(
|
||||
operation,
|
||||
"capacity",
|
||||
`The host ran out of process, memory or file-descriptor capacity (${code}) to start ${provider}.`,
|
||||
{ spawn_error: code, command },
|
||||
{
|
||||
cause,
|
||||
retryable: true,
|
||||
remediationAction: `The host ran out of process, memory or file-descriptor capacity (${code}). Close unused processes or files, or raise the process or open-file limit of the REA process, then retry; ${setting} does not need to change.`,
|
||||
diagnostics: {
|
||||
boundary: "host-capacity",
|
||||
command,
|
||||
system_code: code,
|
||||
},
|
||||
...ownedCleanupOptions(cause),
|
||||
},
|
||||
);
|
||||
}
|
||||
if (
|
||||
earlyFailure === undefined &&
|
||||
(capture === undefined ||
|
||||
|
||||
@@ -132,7 +132,7 @@ export const execFileOutputFailure = (
|
||||
};
|
||||
|
||||
/** Spawn errnos reporting exhausted host capacity rather than an unusable command. */
|
||||
const HOST_SPAWN_CAPACITY_CODES: ReadonlySet<string> = new Set([
|
||||
export const HOST_SPAWN_CAPACITY_CODES: ReadonlySet<string> = new Set([
|
||||
"EAGAIN",
|
||||
"EMFILE",
|
||||
"ENFILE",
|
||||
|
||||
@@ -63,6 +63,122 @@ it.each(["ENOENT", "EACCES", "EPERM", "ENOTDIR"] as const)(
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["EAGAIN", "EMFILE", "ENFILE", "ENOMEM"] as const)(
|
||||
"treats objdump host capacity spawn failure %s as retryable resource constraint without recording launch failure",
|
||||
async (code) => {
|
||||
const { directory, path } = await createArtifact();
|
||||
const command = resolve(directory, "configured-objdump");
|
||||
const hostFailure = Object.assign(
|
||||
new Error("controlled host capacity rejection"),
|
||||
{ code },
|
||||
);
|
||||
const service = new TestReverseEngineeringService({
|
||||
environment: { REA_OBJDUMP_COMMAND: command },
|
||||
runOwned: async () => {
|
||||
throw new OwnedCommandFailure("process", "launch failed", null, null, {
|
||||
cause: hostFailure,
|
||||
});
|
||||
},
|
||||
});
|
||||
try {
|
||||
for (const input of [
|
||||
{ operation: "architectures" },
|
||||
{ path, operation: "file_headers" },
|
||||
]) {
|
||||
const result = await service.inspectWithObjdump(input);
|
||||
if (result.ok)
|
||||
throw new Error("Expected host capacity resource constraint failure");
|
||||
const projected = projectAnalysisError(result.error);
|
||||
expect(projected).toMatchObject({
|
||||
code: "resource_constraint",
|
||||
retryable: true,
|
||||
details: {
|
||||
resource: "capacity",
|
||||
reported_limits: {
|
||||
spawn_error: code,
|
||||
command,
|
||||
},
|
||||
diagnostics: {
|
||||
boundary: "host-capacity",
|
||||
command,
|
||||
system_code: code,
|
||||
},
|
||||
},
|
||||
remediation: {
|
||||
action: expect.stringContaining(
|
||||
"REA_OBJDUMP_COMMAND does not need to change",
|
||||
),
|
||||
},
|
||||
});
|
||||
expect(projected.message).toContain(code);
|
||||
expect(projected.remediation.action).toContain(code);
|
||||
}
|
||||
expect(service.observedLaunchFailures()).toEqual({});
|
||||
} finally {
|
||||
await service.close();
|
||||
await rm(directory, { recursive: true, force: true });
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["EAGAIN", "EMFILE", "ENFILE", "ENOMEM"] as const)(
|
||||
"treats rizin host capacity spawn failure %s as retryable resource constraint without recording launch failure",
|
||||
async (code) => {
|
||||
const { directory, path } = await createArtifact();
|
||||
const command = resolve(directory, "configured-rizin");
|
||||
const hostFailure = Object.assign(
|
||||
new Error("controlled host capacity rejection"),
|
||||
{ code },
|
||||
);
|
||||
const service = new TestReverseEngineeringService({
|
||||
environment: { REA_RIZIN_COMMAND: command },
|
||||
runOwned: async () => {
|
||||
throw new OwnedCommandFailure("process", "launch failed", null, null, {
|
||||
cause: hostFailure,
|
||||
});
|
||||
},
|
||||
});
|
||||
try {
|
||||
const result = await service.executeRizinCommand({
|
||||
path,
|
||||
command: "iI",
|
||||
});
|
||||
if (result.ok)
|
||||
throw new Error(
|
||||
"Expected rizin host capacity resource constraint failure",
|
||||
);
|
||||
const projected = projectAnalysisError(result.error);
|
||||
expect(projected).toMatchObject({
|
||||
code: "resource_constraint",
|
||||
retryable: true,
|
||||
details: {
|
||||
resource: "capacity",
|
||||
reported_limits: {
|
||||
spawn_error: code,
|
||||
command,
|
||||
},
|
||||
diagnostics: {
|
||||
boundary: "host-capacity",
|
||||
command,
|
||||
system_code: code,
|
||||
},
|
||||
},
|
||||
remediation: {
|
||||
action: expect.stringContaining(
|
||||
"REA_RIZIN_COMMAND does not need to change",
|
||||
),
|
||||
},
|
||||
});
|
||||
expect(projected.message).toContain(code);
|
||||
expect(projected.remediation.action).toContain(code);
|
||||
expect(service.observedLaunchFailures()).toEqual({});
|
||||
} finally {
|
||||
await service.close();
|
||||
await rm(directory, { recursive: true, force: true });
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it("preserves target-read permission diagnostics before provider launch", async () => {
|
||||
let launches = 0;
|
||||
const path = resolve("read-denied-artifact");
|
||||
|
||||
Reference in New Issue
Block a user