fix(rizin): report held file work when the service closes

close() aborted active calls, awaited their results and retried process
cleanup, then resolved, although a call that had returned could still
hold a stat, access or stream step that an unresponsive mount had not
answered. Waiting for that work could hang shutdown on a mount that
never answers, so close now fails instead with a cleanup error that
names file_system_work and counts the calls holding it
(operations_awaiting_file_work), and a later close checks again, as it
does for retained provider processes.
This commit is contained in:
Entrpi committed 2026-11-04 12:19:34 +11:00
1 parent 889de8411e
commit ad4a22b329
3 files changed
+50 -18

No files matched your search

+3 -1
View File
@@ -175,7 +175,9 @@ closes, so a stalled close also reaches the deadline. A call that returns while
work it left behind is still running keeps its place among the eight
concurrent objdump and rizin operations until that work returns; a call that
only waited for another call's work does not. The capacity error counts such
calls as `operations_awaiting_file_work`.
calls as `operations_awaiting_file_work`. Closing the service does not wait for
that work: it fails with a cleanup error that names the held
`file_system_work` and counts the calls, and a later close checks again.
Captured stdout and stderr are retained up to a 16 MiB combined limit; `output_truncated` marks output beyond that limit. One-shot commands use the `command_timeout_ms` budget described above. That 16 MiB cap has no runtime override. A typed failure's `captured_output` marks a stream that held invalid UTF-8 with `stdout_invalid_utf8` or `stderr_invalid_utf8`.
@@ -230,7 +230,12 @@ export class ReverseEngineeringService {
return failure === undefined ? ok(null) : err(failure);
}
/** Retry cleanup for provider process groups retained after an incomplete stop. */
/**
* Retry cleanup for provider process groups retained after an incomplete
* stop. File work that calls left behind cannot be cancelled, so close
* reports it instead of waiting for a mount that may never answer; a later
* close checks again.
*/
close(): Promise<void> {
this.#closing = true;
this.#closePromise ??= this.#closeActiveOperationsAndCleanup().catch(
@@ -249,6 +254,16 @@ export class ReverseEngineeringService {
const cleanup = await this.retryCleanup();
if (!cleanup.ok) throw cleanup.error;
const awaiting = this.#awaitingFileWork.size;
if (awaiting > 0) {
const reason = `${String(awaiting)} reverse-engineering ${awaiting === 1 ? "call still holds" : "calls still hold"} file-system work that an unresponsive mount has not returned, which REA cannot cancel.`;
throw new AnalysisOutputError("reverse_engineering_cleanup", reason, {
cleanup: { reason, resources: ["file_system_work"] },
diagnostics: { operations_awaiting_file_work: awaiting },
remediationAction:
"Close again once the mount answers; the file work ends when its system call returns.",
});
}
}
async inspectWithObjdump(
@@ -534,6 +534,7 @@ posix.each(["cancellation", "deadline"] as const)(
const { executable, path } = await rizinExecutableFixture();
const lookupStarted = gate();
const release = gate();
let stalled: Promise<unknown> | undefined;
const run = versionProbeRunner(() => "rizin 0.9.1 @ linux-x86-64");
const service = new TestReverseEngineeringService({
run,
@@ -541,12 +542,12 @@ posix.each(["cancellation", "deadline"] as const)(
lookup: (command, directory, searchPath, bounds) =>
lookupExecutable(command, directory, searchPath, {
...bounds,
stat: async (target) => {
if (target === executable) {
lookupStarted.open();
await release.opened;
}
return stat(target);
stat: (target) => {
if (target !== executable) return stat(target);
lookupStarted.open();
const check = release.opened.then(() => stat(target));
stalled = check;
return check;
},
}),
environment: { REA_RIZIN_COMMAND: "rizin", PATH: dirname(executable) },
@@ -587,12 +588,23 @@ posix.each(["cancellation", "deadline"] as const)(
artifact_sha256: await sha256Of(path),
});
expect(run).not.toHaveBeenCalled();
// Closing does not wait for the abandoned file-system call.
await within(service.close(), "service close");
// Closing does not wait for the abandoned file-system call, but it
// reports that the call still holds it.
await expect(
within(service.close(), "service close"),
).rejects.toMatchObject({
cleanup: { resources: ["file_system_work"] },
diagnostics: { operations_awaiting_file_work: 1 },
});
release.open();
await stalled;
await new Promise((resolve) => setImmediate(resolve));
await within(service.close(), "service close after the mount answers");
} finally {
release.open();
caller.abort("test cleanup");
await Promise.allSettled(pending);
await Promise.allSettled([...pending, stalled]);
await new Promise((resolve) => setImmediate(resolve));
await service.close();
}
},
@@ -1099,18 +1111,19 @@ posix.each(["deadline", "cancellation"] as const)(
const { executable, path } = await rizinExecutableFixture();
const digestStarted = gate();
const release = gate();
let stalled: Promise<unknown> | undefined;
const run = versionProbeRunner(() => "rizin 0.9.1 @ linux-x86-64");
const service = new TestReverseEngineeringService({
run,
lookup: lookupExecutable,
environment: { REA_RIZIN_COMMAND: "rizin", PATH: dirname(executable) },
// Only the executable's digest stalls, past the call's deadline.
stat: async (target) => {
if (target === executable) {
digestStarted.open();
await release.opened;
}
return stat(target);
stat: (target) => {
if (target !== executable) return stat(target);
digestStarted.open();
const check = release.opened.then(() => stat(target));
stalled = check;
return check;
},
});
const caller = new AbortController();
@@ -1151,7 +1164,9 @@ posix.each(["deadline", "cancellation"] as const)(
} finally {
release.open();
caller.abort("test cleanup");
await Promise.allSettled(pending);
// The service holds the stalled stat until it returns.
await Promise.allSettled([...pending, stalled]);
await new Promise((resolve) => setImmediate(resolve));
await service.close();
}
},