summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Hagemeister <marvin@deno.com>2024-07-10 10:05:41 +0200
committerGitHub <noreply@github.com>2024-07-10 10:05:41 +0200
commit2a86edf0afd65af3020c8e6ad84e26d5a687e535 (patch)
treeed10043cbbd8d1e5f6ff147975a787f09f35b952
parent92d567d3562600b2b06791353eeccf8f1d5c4f0f (diff)
fix(node/http): don't error if request destroyed before send (#24497)
A request can be destroyed before it was even made in the Node http API. We errored on that. This issue was discovered in the JSDOM test suite.
-rw-r--r--ext/node/polyfills/http.ts5
-rw-r--r--tests/unit_node/http_test.ts9
2 files changed, 13 insertions, 1 deletions
diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts
index 3059da3a6..0ef245902 100644
--- a/ext/node/polyfills/http.ts
+++ b/ext/node/polyfills/http.ts
@@ -322,6 +322,7 @@ class ClientRequest extends OutgoingMessage {
insecureHTTPParser: boolean;
useChunkedEncodingByDefault: boolean;
path: string;
+ _req: { requestRid: number; cancelHandleRid: number | null } | undefined;
constructor(
input: string | URL,
@@ -819,7 +820,9 @@ class ClientRequest extends OutgoingMessage {
if (rid) {
core.tryClose(rid);
}
- if (this._req.cancelHandleRid !== null) {
+
+ // Request might be closed before we actually made it
+ if (this._req !== undefined && this._req.cancelHandleRid !== null) {
core.tryClose(this._req.cancelHandleRid);
}
// If we're aborting, we don't care about any more response data.
diff --git a/tests/unit_node/http_test.ts b/tests/unit_node/http_test.ts
index a053f3a27..71043d985 100644
--- a/tests/unit_node/http_test.ts
+++ b/tests/unit_node/http_test.ts
@@ -994,6 +994,15 @@ Deno.test(
},
);
+Deno.test(
+ "[node/http] client destroy before sending request should not error",
+ () => {
+ const request = http.request("http://localhost:5929/");
+ // Calling this would throw
+ request.destroy();
+ },
+);
+
Deno.test("[node/http] node:http exports globalAgent", async () => {
const http = await import("node:http");
assert(