diff --git a/ext/node/polyfills/_tls_wrap.ts b/ext/node/polyfills/_tls_wrap.ts index 08275d4110..a251904b24 100644 --- a/ext/node/polyfills/_tls_wrap.ts +++ b/ext/node/polyfills/_tls_wrap.ts @@ -85,7 +85,8 @@ export class TLSSocket extends net.Socket { constructor(socket: any, opts: any = kEmptyObject) { const tlsOptions = { ...opts }; - const hostname = opts.servername ?? opts.host ?? socket._host; + const hostname = opts.servername ?? opts.host ?? socket?._host ?? + "localhost"; tlsOptions.hostname = hostname; const _cert = tlsOptions?.secureContext?.cert; diff --git a/tests/unit_node/tls_test.ts b/tests/unit_node/tls_test.ts index f34d9efb5b..cfdc565c77 100644 --- a/tests/unit_node/tls_test.ts +++ b/tests/unit_node/tls_test.ts @@ -71,7 +71,6 @@ Deno.test("tls.connect makes tls connection", async () => { await delay(200); const conn = tls.connect({ - host: "localhost", port, secureContext: { ca: rootCaCert,