Skip to content

Commit 70c03a8

Browse files
authoredOct 23, 2024··
fix(cache): try/catch package file cache cleanup separately (#32074)
1 parent d9543ec commit 70c03a8

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed
 

‎lib/util/cache/package/file.ts

+17-11
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,12 @@ export function init(cacheDir: string): string {
7676

7777
export async function cleanup(): Promise<void> {
7878
logger.debug('Checking file package cache for expired items');
79-
try {
80-
let totalCount = 0;
81-
let deletedCount = 0;
82-
const startTime = Date.now();
83-
for await (const item of cacache.ls.stream(cacheFileName)) {
79+
let totalCount = 0;
80+
let deletedCount = 0;
81+
const startTime = Date.now();
82+
let errorCount = 0;
83+
for await (const item of cacache.ls.stream(cacheFileName)) {
84+
try {
8485
totalCount += 1;
8586
const cachedItem = item as unknown as cacache.CacheObject;
8687
const res = await cacache.get(cacheFileName, cachedItem.key);
@@ -99,12 +100,17 @@ export async function cleanup(): Promise<void> {
99100
await cacache.rm.content(cacheFileName, cachedItem.integrity);
100101
deletedCount += 1;
101102
}
103+
} catch (err) /* istanbul ignore next */ {
104+
logger.trace({ err }, 'Error cleaning up cache entry');
105+
errorCount += 1;
102106
}
103-
const durationMs = Math.round(Date.now() - startTime);
104-
logger.debug(
105-
`Deleted ${deletedCount} of ${totalCount} file cached entries in ${durationMs}ms`,
106-
);
107-
} catch (err) /* istanbul ignore next */ {
108-
logger.warn({ err }, 'Error cleaning up expired file cache');
109107
}
108+
// istanbul ignore if: cannot reproduce error
109+
if (errorCount > 0) {
110+
logger.debug(`Error count cleaning up cache: ${errorCount}`);
111+
}
112+
const durationMs = Math.round(Date.now() - startTime);
113+
logger.debug(
114+
`Deleted ${deletedCount} of ${totalCount} file cached entries in ${durationMs}ms`,
115+
);
110116
}

0 commit comments

Comments
 (0)
Please sign in to comment.