From 579276ee2d9d2e103e0a93d7f5dfd3073e5b2f52 Mon Sep 17 00:00:00 2001 From: xCyanGrizzly Date: Sat, 2 May 2026 23:24:08 +0200 Subject: [PATCH] fix: widen hash lock try/finally to prevent lock leak on error paths --- worker/src/worker.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/worker/src/worker.ts b/worker/src/worker.ts index bc1e742..384d2f6 100644 --- a/worker/src/worker.ts +++ b/worker/src/worker.ts @@ -1042,11 +1042,16 @@ async function processOneArchiveSet( return null; } + let entries: { path: string; fileName: string; extension: string | null; compressedSize: bigint; uncompressedSize: bigint; crc32: string | null }[] = []; + let creator: string | null = null; + const tags: string[] = []; + let stub: { id: string } | null = null; + + try { // Re-check after acquiring lock: another worker may have finished between // the first check above and this point. const existsAfterLock = await packageExistsByHash(contentHash); if (existsAfterLock) { - await releaseHashLock(contentHash); counters.zipsDuplicate++; accountLog.debug( { fileName: archiveName, hash: contentHash.slice(0, 16) }, @@ -1065,7 +1070,6 @@ async function processOneArchiveSet( totalFiles: totalSets, }); - let entries: { path: string; fileName: string; extension: string | null; compressedSize: bigint; uncompressedSize: bigint; crc32: string | null }[] = []; try { if (archiveSet.type === "ZIP") { entries = await readZipCentralDirectory(tempPaths); @@ -1167,12 +1171,6 @@ async function processOneArchiveSet( ); } - // Hoist creator/tags so they're visible after try block for logging - let creator: string | null = null; - const tags: string[] = []; - - let stub: { id: string } | null = null; - try { // ── Uploading ── // Check if a prior run already uploaded this file (orphaned upload scenario: // file reached Telegram but DB write failed or worker crashed before indexing)