diff --git a/docs/reverse-engineering-tools.md b/docs/reverse-engineering-tools.md index d0c1d7aec7..2a3a685c0e 100644 --- a/docs/reverse-engineering-tools.md +++ b/docs/reverse-engineering-tools.md @@ -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`. diff --git a/src/application/reverse/ReverseEngineeringService.ts b/src/application/reverse/ReverseEngineeringService.ts index fe91506d84..6835b9c59a 100644 --- a/src/application/reverse/ReverseEngineeringService.ts +++ b/src/application/reverse/ReverseEngineeringService.ts @@ -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 { 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( diff --git a/tests/boundary/filesystem/reverseEngineeringToolIdentity.test.ts b/tests/boundary/filesystem/reverseEngineeringToolIdentity.test.ts index 896a117981..a89e9ea408 100644 --- a/tests/boundary/filesystem/reverseEngineeringToolIdentity.test.ts +++ b/tests/boundary/filesystem/reverseEngineeringToolIdentity.test.ts @@ -534,6 +534,7 @@ posix.each(["cancellation", "deadline"] as const)( const { executable, path } = await rizinExecutableFixture(); const lookupStarted = gate(); const release = gate(); + let stalled: Promise | 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 | 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(); } },