Skip to content

Commit 2536087

Browse files
committed
fix: ensure background work is finished when response has 3xx or 5xx status code
1 parent 62ed00c commit 2536087

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/run/handlers/server.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export default async (request: Request) => {
100100

101101
// Contrary to the docs, this resolves when the headers are available, not when the stream closes.
102102
// See https://github.com/fastly/http-compute-js/blob/main/src/http-compute-js/http-server.ts#L168-L173
103-
const response = await toComputeResponse(resProxy)
103+
let response = await toComputeResponse(resProxy)
104104

105105
if (requestContext.responseCacheKey) {
106106
span.setAttribute('responseCacheKey', requestContext.responseCacheKey)
@@ -121,7 +121,7 @@ export default async (request: Request) => {
121121
// TODO: Remove once a fix has been rolled out.
122122
if ((response.status > 300 && response.status < 400) || response.status >= 500) {
123123
const body = await response.text()
124-
return new Response(body || null, response)
124+
response = new Response(body || null, response)
125125
}
126126

127127
const keepOpenUntilNextFullyRendered = new TransformStream({

0 commit comments

Comments
 (0)