0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-02-08 07:16:56 -05:00

fix(node/http): don't leak resources on destroyed request (#20040)

Closes https://github.com/denoland/deno/issues/19828
This commit is contained in:
Bartek Iwańczuk 2023-08-29 14:13:58 +02:00
parent cd460bbf7e
commit 430c1f635a
No known key found for this signature in database
GPG key ID: 0C6BCDDC3B3AD750
2 changed files with 41 additions and 0 deletions

View file

@ -777,3 +777,37 @@ Deno.test("[node/http] server emits error if addr in use", async () => {
`Wrong error: ${err.message}`,
);
});
Deno.test(
"[node/http] client destroy doesn't leak",
{ permissions: { net: true } },
async () => {
const ac = new AbortController();
let timerId;
const server = Deno.serve(
{ port: 5929, signal: ac.signal },
async (_req) => {
await new Promise((resolve) => {
timerId = setTimeout(resolve, 5000);
});
return new Response("hello");
},
);
const promise = deferred();
const request = http.request("http://localhost:5929/");
request.on("error", promise.reject);
request.on("close", () => {});
request.end();
setTimeout(() => {
request.destroy(new Error());
promise.resolve();
}, 100);
await promise;
clearTimeout(timerId);
ac.abort();
await server.finished;
},
);

View file

@ -771,6 +771,13 @@ class ClientRequest extends OutgoingMessage {
}
this.destroyed = true;
const rid = this._client?.rid;
if (rid) {
core.tryClose(rid);
}
if (this._req.cancelHandleRid !== null) {
core.tryClose(this._req.cancelHandleRid);
}
// If we're aborting, we don't care about any more response data.
if (this.res) {
this.res._dump();