Skip to content

Commit 43430b3

Browse files
committed
prevent potential memleak
1 parent e9415f5 commit 43430b3

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

apps/coordinator/src/checkpointer.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,12 @@ export class Checkpointer {
399399
const controller = new AbortController();
400400
this.#abortControllers.set(runId, controller);
401401

402+
const onAbort = () => {
403+
this.#logger.error("Checkpoint aborted", { options });
404+
controller.signal.removeEventListener("abort", onAbort);
405+
};
406+
controller.signal.addEventListener("abort", onAbort);
407+
402408
const shortCode = nanoid(8);
403409
const imageRef = this.#getImageRef(projectRef, deploymentVersion, shortCode);
404410
const exportLocation = this.#getExportLocation(projectRef, deploymentVersion, shortCode);
@@ -426,6 +432,9 @@ export class Checkpointer {
426432
} catch (error) {
427433
this.#logger.error("Error during cleanup", { ...metadata, error });
428434
}
435+
436+
this.#abortControllers.delete(runId);
437+
controller.signal.removeEventListener("abort", onAbort);
429438
};
430439

431440
try {
@@ -550,8 +559,6 @@ export class Checkpointer {
550559

551560
return { success: false, reason: "ERROR" };
552561
} finally {
553-
this.#abortControllers.delete(runId);
554-
555562
await cleanup();
556563

557564
if (controller.signal.aborted) {

apps/coordinator/src/exec.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,7 @@ export class Exec {
3333

3434
constructor(opts: ExecOptions) {
3535
this.logger = opts.logger ?? new SimpleLogger();
36-
37-
if (opts.abortSignal) {
38-
this.abortSignal = opts.abortSignal;
39-
this.abortSignal.addEventListener("abort", () => {
40-
this.logger.error("abort signal triggered");
41-
});
42-
}
36+
this.abortSignal = opts.abortSignal;
4337

4438
this.logOutput = opts.logOutput ?? true;
4539
this.trimArgs = opts.trimArgs ?? true;

0 commit comments

Comments
 (0)