feat(ghidra): make the startup deadline configurable (#974)
* feat(ghidra): make the startup deadline configurable Large binaries (an 8 MB PE with about 20,000 functions) need more than the fixed 330 s for import and full auto-analysis, so every first request timed out. REA_GHIDRA_STARTUP_TIMEOUT_MS overrides the deadline in milliseconds; absent, empty or invalid values keep the 330 s default. * docs(ghidra): document REA_GHIDRA_STARTUP_TIMEOUT_MS * fix(ghidra): parse startup deadlines through runtime configuration --------- Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
@@ -24,7 +24,6 @@ import { err, ok, type Result } from "../domain/result.js";
|
||||
import type { Logger } from "../logger.js";
|
||||
import { GhidraClient } from "./GhidraClient.js";
|
||||
import type { GhidraClientOptions } from "./GhidraClientTypes.js";
|
||||
import { GHIDRA_STARTUP_TIMEOUT_MS } from "./GhidraDefaults.js";
|
||||
import {
|
||||
isGhidraFunctionOperation,
|
||||
parseGhidraFunctionInput,
|
||||
@@ -132,6 +131,7 @@ export const createGhidraProviderClient = (input: {
|
||||
]
|
||||
: [];
|
||||
const client = clientFactory({
|
||||
startupTimeoutMs: config.ghidraStartupTimeoutMs,
|
||||
platform: installation.platform,
|
||||
launcher: new GhidraHeadlessLauncher({
|
||||
analyzeHeadlessPath: prerequisites.value.analyzeHeadlessPath,
|
||||
@@ -204,7 +204,13 @@ export const createGhidraProviderClient = (input: {
|
||||
if (operation === "health") {
|
||||
const started = await client.start(options?.signal);
|
||||
if (!started.ok)
|
||||
return err(projectSessionError(operation, started.error));
|
||||
return err(
|
||||
projectSessionError(
|
||||
operation,
|
||||
started.error,
|
||||
config.ghidraStartupTimeoutMs,
|
||||
),
|
||||
);
|
||||
const failed = await checkExtensions(operation, started.value);
|
||||
if (failed !== undefined) return err(failed);
|
||||
return ok(
|
||||
@@ -221,7 +227,13 @@ export const createGhidraProviderClient = (input: {
|
||||
if (extensions.length > 0) {
|
||||
const started = await client.start(options?.signal);
|
||||
if (!started.ok)
|
||||
return err(projectSessionError(operation, started.error));
|
||||
return err(
|
||||
projectSessionError(
|
||||
operation,
|
||||
started.error,
|
||||
config.ghidraStartupTimeoutMs,
|
||||
),
|
||||
);
|
||||
const failed = await checkExtensions(operation, started.value);
|
||||
if (failed !== undefined) return err(failed);
|
||||
}
|
||||
@@ -230,7 +242,14 @@ export const createGhidraProviderClient = (input: {
|
||||
input.value,
|
||||
options?.signal === undefined ? {} : { signal: options.signal },
|
||||
);
|
||||
if (!called.ok) return err(projectSessionError(operation, called.error));
|
||||
if (!called.ok)
|
||||
return err(
|
||||
projectSessionError(
|
||||
operation,
|
||||
called.error,
|
||||
config.ghidraStartupTimeoutMs,
|
||||
),
|
||||
);
|
||||
const result = isGhidraFunctionOperation(operation)
|
||||
? parseGhidraFunctionResult(operation, called.value)
|
||||
: parseGhidraInventoryResult(operation, called.value);
|
||||
@@ -242,7 +261,12 @@ export const createGhidraProviderClient = (input: {
|
||||
operation,
|
||||
result.value,
|
||||
client,
|
||||
(failure) => projectSessionError(operation, failure),
|
||||
(failure) =>
|
||||
projectSessionError(
|
||||
operation,
|
||||
failure,
|
||||
config.ghidraStartupTimeoutMs,
|
||||
),
|
||||
);
|
||||
if (!attested.ok) return attested;
|
||||
normalized = attested.value;
|
||||
@@ -320,6 +344,7 @@ const unavailableClient = (failure: AnalysisError): AnalysisClient => ({
|
||||
const projectSessionError = (
|
||||
operation: AnalysisOperation,
|
||||
failure: GhidraSessionError,
|
||||
startupTimeoutMs: number,
|
||||
): AnalysisError => {
|
||||
if (failure.cause instanceof AnalysisAccessDeniedError)
|
||||
return new AnalysisAccessDeniedError(
|
||||
@@ -348,7 +373,7 @@ const projectSessionError = (
|
||||
if (failure.kind === "timeout" || failure.kind === "analysis_timeout")
|
||||
return new AnalysisTimeoutError(
|
||||
operation,
|
||||
failure.timeoutMs ?? GHIDRA_STARTUP_TIMEOUT_MS,
|
||||
failure.timeoutMs ?? startupTimeoutMs,
|
||||
);
|
||||
if (failure.kind === "remote" && failure.remoteCode === "decompile_cancelled")
|
||||
return new AnalysisCancelledError(operation);
|
||||
|
||||
Reference in New Issue
Block a user