From 019445dffb0503a638739aa8ce5f6f7ca637e21f Mon Sep 17 00:00:00 2001 From: Dylan Jeffers Date: Mon, 10 Aug 2026 16:39:53 -0700 Subject: [PATCH] fix(archiver): clear the waitForSpace timeout on the success path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-up to #88. `waitForSpace` never cleared its timeout timer, so every satisfied space claim left a pending timer alive for the full `maxDiskSpaceWaitSeconds`. The late fire is harmless on its own — `Promise.race` has already settled and both branches are handled, so there's no unhandled rejection — but this is a long-lived worker and #88 is specifically about not leaking per-job resources. Clear it in a `finally` so both the success and failure paths release the timer. Co-Authored-By: Claude Opus 5 --- apps/archiver/src/workers/spaceManager.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/apps/archiver/src/workers/spaceManager.ts b/apps/archiver/src/workers/spaceManager.ts index 4fe4b9c..641faeb 100644 --- a/apps/archiver/src/workers/spaceManager.ts +++ b/apps/archiver/src/workers/spaceManager.ts @@ -132,8 +132,9 @@ export function createSpaceManager(options: SpaceManagerOptions) { } })() + let timeoutTimer: ReturnType | undefined const timeoutPromise = new Promise((_, reject) => { - setTimeout(() => { + timeoutTimer = setTimeout(() => { loopController.abort() reject( new SpaceManagerError( @@ -151,6 +152,13 @@ export function createSpaceManager(options: SpaceManagerOptions) { loopController.abort() await removeFromQueue(token) throw error + } finally { + // Clear the timer on the success path too. Without this every + // satisfied claim leaves a pending timer alive for the full + // maxDiskSpaceWaitSeconds — harmless in isolation, but this is a + // long-lived worker and the whole point of this change is to stop + // leaking per-job resources. + clearTimeout(timeoutTimer) } })() }