mirror of
https://github.com/denoland/deno.git
synced 2025-01-19 04:16:00 -05:00
fix(ext/node): propagate socket error to client request object (#27678)
Co-authored-by: Satya Rohith <me@satyarohith.com>
This commit is contained in:
parent
94dc5b16f5
commit
339bc44c58
2 changed files with 24 additions and 2 deletions
|
@ -455,8 +455,13 @@ class ClientRequest extends OutgoingMessage {
|
|||
(async () => {
|
||||
try {
|
||||
const parsedUrl = new URL(url);
|
||||
let baseConnRid =
|
||||
this.socket._handle[kStreamBaseField][internalRidSymbol];
|
||||
const handle = this.socket._handle;
|
||||
if (!handle) {
|
||||
// Using non-standard socket. There's no way to handle this type of socket.
|
||||
// This should be only happening in artificial test cases
|
||||
return;
|
||||
}
|
||||
let baseConnRid = handle[kStreamBaseField][internalRidSymbol];
|
||||
if (this._encrypted) {
|
||||
[baseConnRid] = op_tls_start({
|
||||
rid: baseConnRid,
|
||||
|
@ -637,6 +642,12 @@ class ClientRequest extends OutgoingMessage {
|
|||
};
|
||||
this.socket = socket;
|
||||
this.emit("socket", socket);
|
||||
socket.once("error", (err) => {
|
||||
// This callback loosely follow `socketErrorListener` in Node.js
|
||||
// https://github.com/nodejs/node/blob/f16cd10946ca9ad272f42b94f00cf960571c9181/lib/_http_client.js#L509
|
||||
emitErrorEvent(this, err);
|
||||
socket.destroy(err);
|
||||
});
|
||||
if (socket.readyState === "opening") {
|
||||
socket.on("connect", onConnect);
|
||||
} else {
|
||||
|
|
|
@ -1881,3 +1881,14 @@ Deno.test("[node/http] decompress brotli response", {
|
|||
"localhost:3000",
|
||||
], ["user-agent", "Deno/2.1.1"]]);
|
||||
});
|
||||
|
||||
Deno.test("[node/http] an error with DNS propagates to request object", async () => {
|
||||
const { resolve, promise } = Promise.withResolvers<void>();
|
||||
const req = http.request("http://invalid-hostname.test", () => {});
|
||||
req.on("error", (err) => {
|
||||
assertEquals(err.name, "Error");
|
||||
assertEquals(err.message, "getaddrinfo ENOTFOUND invalid-hostname.test");
|
||||
resolve();
|
||||
});
|
||||
await promise;
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue