diff --git a/src/core/git/gitHubArchive.ts b/src/core/git/gitHubArchive.ts index e5e96fa57..209592735 100644 --- a/src/core/git/gitHubArchive.ts +++ b/src/core/git/gitHubArchive.ts @@ -112,7 +112,7 @@ const downloadAndExtractArchive = async ( deps: ArchiveDownloadDeps = defaultDeps, ): Promise => { const controller = new AbortController(); - const timeoutId = setTimeout(() => controller.abort(), timeout); + const timeoutId = setTimeout(controller.abort.bind(controller), timeout); try { const response = await deps.fetch(archiveUrl, { diff --git a/website/client/composables/usePackRequest.ts b/website/client/composables/usePackRequest.ts index f5b36beeb..9fb583119 100644 --- a/website/client/composables/usePackRequest.ts +++ b/website/client/composables/usePackRequest.ts @@ -74,11 +74,8 @@ export function usePackRequest() { inputRepositoryUrl.value = inputUrl.value; // Set up automatic timeout - const timeoutId = setTimeout(() => { - if (requestController) { - requestController.abort('timeout'); - } - }, TIMEOUT_MS); + // Use .bind() to avoid capturing the surrounding scope in the closure + const timeoutId = setTimeout(requestController.abort.bind(requestController, 'timeout'), TIMEOUT_MS); try { await handlePackRequest( diff --git a/website/server/src/domains/pack/utils/cache.ts b/website/server/src/domains/pack/utils/cache.ts index dff638017..a7ea0f195 100644 --- a/website/server/src/domains/pack/utils/cache.ts +++ b/website/server/src/domains/pack/utils/cache.ts @@ -13,12 +13,20 @@ interface CacheEntry { export class RequestCache { private cache: Map = new Map(); private readonly ttl: number; + private readonly cleanupIntervalId: ReturnType; constructor(ttlInSeconds = 60) { this.ttl = ttlInSeconds * 1000; // Set up periodic cache cleanup - setInterval(() => this.cleanup(), ttlInSeconds * 1000); + // Use .bind() to avoid capturing the surrounding scope in the closure + this.cleanupIntervalId = setInterval(this.cleanup.bind(this), ttlInSeconds * 1000); + this.cleanupIntervalId.unref(); + } + + dispose(): void { + clearInterval(this.cleanupIntervalId); + this.cache.clear(); } async get(key: string): Promise {