oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.26k stars 2.69k forks source link

Invalid address from http.Server #4358

Closed sirenkovladd closed 4 months ago

sirenkovladd commented 1 year ago

What version of Bun is running?

0.8.1+16b4bf341acc0f4804f0b6bdf5298c180cd00366

What platform is your computer?

Linux 6.2.0-26-generic x86_64 x86_64

What steps can reproduce the bug?

const server = require('http').createServer();
server.listen(3000, 'localhost', () => {
  console.log(JSON.stringify(server.address()))
  process.exit(0);
});

What is the expected behavior?

❯ node bug.js 
{"address":"127.0.0.1","family":"IPv4","port":3000}

What do you see instead?

❯ bun bug.js
{"address":"localhost","family":"IPv4","port":3000}

Additional information

(http.Server instanceof net.Server)

https://github.com/nodejs/node/blob/v20.5.1/lib/net.js#L2004

https://github.com/nodejs/node/blob/v20.5.1/lib/net.js#L2062-L2073

sirenkovladd commented 1 year ago

@Jarred-Sumner, is it possible to apply this PR because it blocks the use of fastify-cli?

330 |       family: isIPv6(address) ? "IPv6" : "IPv4",
331 |       port: this.#server.port
332 |     };
333 |   }
334 | 
335 |   listen(port, host, backlog, onListen) {
                   ^
error: Failed to start server. Is port 3000 in use?
      at listen (node:http:335:16)
      at <cut>/node_modules/fastify/lib/server.js:234:6
      at <cut>/node_modules/fastify/lib/server.js:189:10
      at node:dns:11:70
gabriiels commented 1 year ago

https://github.com/oven-sh/bun/issues/1641#issuecomment-1708651616

sirenkovladd commented 1 year ago

So it's a workaround

s1nistr4 commented 1 year ago

Yeah, fastify doesn't work with bun yet.

7f8ddd commented 1 year ago

Yeah, fastify doesn't work with bun yet.

Bun is working with Fastify on the canary release, including with TypeORM. Only issues I've had is related to NAPI libraries, such as node-canvas/canvas. This is with NestJS.

bun upgrade --canary
// TS:
bun add -d bun-types@canary
Jarred-Sumner commented 4 months ago

This bug was fixed in Bun 1.0

/tmp/checky
❯ bun such-work.js
{"address":"::1","family":"IPv6","port":3000}

/tmp/checky
❯ node such-work.js
{"address":"::1","family":"IPv6","port":3000}

/tmp/checky
❯ cat such-work.js
───────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: such-work.js
───────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ const server = require("http").createServer();
   2   │ server.listen(3000, "localhost", () => {
   3   │   console.log(JSON.stringify(server.address()));
   4   │   process.exit(0);
   5   │ });
───────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────