mirror of
https://github.com/denoland/deno.git
synced 2024-11-30 16:40:57 -05:00
fix(ext/http): fix crash in dropped Deno.serve requests (#21252)
Fixes #21250 We were attempting to recycle dropped resource responses too early.
This commit is contained in:
parent
e635d66f4a
commit
45be896436
2 changed files with 71 additions and 62 deletions
|
@ -2727,13 +2727,14 @@ Deno.test(
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
for (const url of ["text", "file", "stream"]) {
|
for (const delay of ["delay", "nodelay"]) {
|
||||||
|
for (const url of ["text", "file", "stream"]) {
|
||||||
// Ensure that we don't panic when the incoming TCP request was dropped
|
// Ensure that we don't panic when the incoming TCP request was dropped
|
||||||
// https://github.com/denoland/deno/issues/20315 and that we correctly
|
// https://github.com/denoland/deno/issues/20315 and that we correctly
|
||||||
// close/cancel the response
|
// close/cancel the response
|
||||||
Deno.test({
|
Deno.test({
|
||||||
permissions: { read: true, write: true, net: true },
|
permissions: { read: true, write: true, net: true },
|
||||||
name: `httpServerTcpCancellation_${url}`,
|
name: `httpServerTcpCancellation_${url}_${delay}`,
|
||||||
fn: async function () {
|
fn: async function () {
|
||||||
const ac = new AbortController();
|
const ac = new AbortController();
|
||||||
const streamCancelled = url == "stream" ? deferred() : undefined;
|
const streamCancelled = url == "stream" ? deferred() : undefined;
|
||||||
|
@ -2764,6 +2765,10 @@ for (const url of ["text", "file", "stream"]) {
|
||||||
}
|
}
|
||||||
waitForRequest.resolve();
|
waitForRequest.resolve();
|
||||||
await waitForAbort;
|
await waitForAbort;
|
||||||
|
|
||||||
|
if (delay == "delay") {
|
||||||
|
await new Promise((r) => setTimeout(r, 1000));
|
||||||
|
}
|
||||||
// Allocate the request body
|
// Allocate the request body
|
||||||
req.body;
|
req.body;
|
||||||
return new Response(respBody);
|
return new Response(respBody);
|
||||||
|
@ -2775,7 +2780,9 @@ for (const url of ["text", "file", "stream"]) {
|
||||||
// Create a POST request and drop it once the server has received it
|
// Create a POST request and drop it once the server has received it
|
||||||
const conn = await Deno.connect({ port: servePort });
|
const conn = await Deno.connect({ port: servePort });
|
||||||
const writer = conn.writable.getWriter();
|
const writer = conn.writable.getWriter();
|
||||||
await writer.write(new TextEncoder().encode(`POST /${url} HTTP/1.0\n\n`));
|
await writer.write(
|
||||||
|
new TextEncoder().encode(`POST /${url} HTTP/1.0\n\n`),
|
||||||
|
);
|
||||||
await waitForRequest;
|
await waitForRequest;
|
||||||
await writer.close();
|
await writer.close();
|
||||||
|
|
||||||
|
@ -2794,6 +2801,7 @@ for (const url of ["text", "file", "stream"]) {
|
||||||
await server.finished;
|
await server.finished;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Deno.test(
|
Deno.test(
|
||||||
|
|
|
@ -716,6 +716,8 @@ pub async fn op_http_set_response_body_resource(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
*http.needs_close_after_finish() = true;
|
||||||
|
|
||||||
set_response(
|
set_response(
|
||||||
http.clone(),
|
http.clone(),
|
||||||
resource.size_hint().1.map(|s| s as usize),
|
resource.size_hint().1.map(|s| s as usize),
|
||||||
|
@ -726,7 +728,6 @@ pub async fn op_http_set_response_body_resource(
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
*http.needs_close_after_finish() = true;
|
|
||||||
http.response_body_finished().await;
|
http.response_body_finished().await;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue