denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
93.41k stars 5.18k forks source link

Bug: node `Server.address()` returns wrong port #24427

Open marvinhagemeister opened 4 days ago

marvinhagemeister commented 4 days ago

Noticed in Koa's test suite that we return the wrong port when calling Server.address(). Instead of the actual port we simply return the user supplied value. In case of 0 where the OS will pick the final port this value will be wrong and leads to test failures in Koa's suite. Running the snippet here in Node gives the actual port.

Steps to reproduce

Run this:

import http from "node:http";

const server = http
  .createServer((req, res) => res.end("hello"))
  .listen(0);

const addr = server.address();
if (addr.port === 0) {
  throw new Error("Didn't return actual port");
}

server.close();

Version: Deno 1.44.4 (git 147411e64 )

marvinhagemeister commented 4 days ago

It looks like we do set the correct port eventually here: https://github.com/denoland/deno/blob/147411e64b22fe74cb258125acab83f9182c9f81/ext/node/polyfills/http.ts#L1760