Skip to content

Commit b6995a5

Browse files
committed
fix: using context.waitUntil after response was already returned is no-op, so need to track it more carefully
1 parent 4ce9230 commit b6995a5

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/run/handlers/cache.cts

+1-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions {
424424
// encode here to deal with non ASCII characters in the key
425425
const tag = `_N_T_${key === '/index' ? '/' : encodeURI(key)}`
426426

427-
purgeEdgeCache(tag)
427+
requestContext?.trackBackgroundWork(purgeEdgeCache(tag))
428428
}
429429
}
430430
})

src/run/handlers/tags-handler.cts

+4-6
Original file line numberDiff line numberDiff line change
@@ -84,23 +84,21 @@ function getCacheTagsFromTagOrTags(tagOrTags: string | string[]): string[] {
8484
.filter(Boolean)
8585
}
8686

87-
export function purgeEdgeCache(tagOrTags: string | string[]): void {
87+
export function purgeEdgeCache(tagOrTags: string | string[]): Promise<void> {
8888
const tags = getCacheTagsFromTagOrTags(tagOrTags)
8989

9090
if (tags.length === 0) {
91-
return
91+
return Promise.resolve()
9292
}
9393

9494
getLogger().debug(`[NextRuntime] Purging CDN cache for: [${tags}.join(', ')]`)
9595

96-
const purgeCachePromise = purgeCache({ tags, userAgent: purgeCacheUserAgent }).catch((error) => {
96+
return purgeCache({ tags, userAgent: purgeCacheUserAgent }).catch((error) => {
9797
// TODO: add reporting here
9898
getLogger()
9999
.withError(error)
100100
.error(`[NextRuntime] Purging the cache for tags [${tags.join(',')}] failed`)
101101
})
102-
103-
getRequestContext()?.trackBackgroundWork(purgeCachePromise)
104102
}
105103

106104
async function doRevalidateTagAndPurgeEdgeCache(tags: string[]): Promise<void> {
@@ -126,7 +124,7 @@ async function doRevalidateTagAndPurgeEdgeCache(tags: string[]): Promise<void> {
126124
}),
127125
)
128126

129-
purgeEdgeCache(tags)
127+
await purgeEdgeCache(tags)
130128
}
131129

132130
export function markTagsAsStaleAndPurgeEdgeCache(tagOrTags: string | string[]) {

0 commit comments

Comments
 (0)