Reverse engineer anything with agents, from app behavior down to native binaries.
TypeScript agent-skillsai-agentsbinary-analysisclaude-codeclicodexcordisdecompilerdeveloper-toolsdshdsh-pluginghidrahopperllmmcpmodel-context-protocolreareverse-engineeringstatic-analysistouhou
fix(artifacts): serialize concurrent cleanup lease releases
morluto16924e275e93
diff --git a/src/artifacts/AnalysisCleanupLease.test.ts b/src/artifacts/AnalysisCleanupLease.test.tsindex 16ea53580..cf94eb23e 100644--- a/src/artifacts/AnalysisCleanupLease.test.ts+++ b/src/artifacts/AnalysisCleanupLease.test.ts@@ -142,3 +142,39 @@ it.each([false, true])(expect(group.cleanupResources).toBeUndefined();},);++it("shares an in-flight release and permits one new attempt after failure", async () => {+ const pending: ((failure?: Error) => void)[] = [];+ let attempts = 0;+ const lease = new AnalysisCleanupLease(() => {+ attempts++;+ return new Promise<void>((resolve, reject) => {+ pending.push((failure) =>+ failure === undefined ? resolve() : reject(failure),+ );+ });+ }, ["owned control"]);+ try {+ const first = lease.release();+ const shared = lease.release();+ const rejected = Promise.allSettled([first, shared]);+ await Promise.resolve();+ expect(attempts).toBe(1);+ const failure = new Error("controlled release failure");+ pending[0]!(failure);+ for (const outcome of await rejected)+ expect(outcome).toEqual({ status: "rejected", reason: failure });+ expect(lease.released).toBe(false);+ const retry = lease.release();+ const sharedRetry = lease.release();+ await Promise.resolve();+ expect(attempts).toBe(2);+ pending[1]!();+ await Promise.all([retry, sharedRetry]);+ expect(lease.released).toBe(true);+ await lease.release();+ expect(attempts).toBe(2);+ } finally {+ for (const settle of pending) settle();+ }+});diff --git a/src/artifacts/AnalysisCleanupLease.ts b/src/artifacts/AnalysisCleanupLease.tsindex d2dc6d917..80049cfc6 100644--- a/src/artifacts/AnalysisCleanupLease.ts+++ b/src/artifacts/AnalysisCleanupLease.ts@@ -6,6 +6,7 @@ import type {/** Link one resource's confirmed release to its originating analysis error. */export class AnalysisCleanupLease {#released = false;+ #releasePromise: Promise<void> | undefined;#errors: WeakRef<AnalysisError>[] = [];readonly #groups = new Set<AnalysisCleanupLeaseGroup>();@@ -56,13 +57,22 @@ export class AnalysisCleanupLease {}}- async release(): Promise<void> {- if (this.#released) return;- await this.cleanup();- this.#released = true;- this.#resolveBoundErrors();- for (const group of this.#groups) group.ownerReleased(this);- this.#groups.clear();+ release(): Promise<void> {+ if (this.#released) return Promise.resolve();+ if (this.#releasePromise !== undefined) return this.#releasePromise;+ const attempt = Promise.resolve()+ .then(async () => {+ await this.cleanup();+ this.#released = true;+ this.#resolveBoundErrors();+ for (const group of this.#groups) group.ownerReleased(this);+ this.#groups.clear();+ })+ .finally(() => {+ if (this.#releasePromise === attempt) this.#releasePromise = undefined;+ });+ this.#releasePromise = attempt;+ return attempt;}/** Binding can follow a concurrent retry that already confirmed release. */