bun icon indicating copy to clipboard operation
bun copied to clipboard

`Bun.serve()` combination of `hostname` and default port causes error on HTTP and HTTPS

Open mangs opened this issue 10 months ago • 0 comments

What version of Bun is running?

1.1.5+1a4bad80b

What platform is your computer?

Darwin 23.4.0 arm64 arm

What steps can reproduce the bug?

[!NOTE] Setting hostname to 0.0.0.0 works correctly (only on macOS; breaks on Linux). Any other value does not unless non-default port values are used for HTTP (80) or HTTPS (443).

  1. If I start Bun.serve() in HTTPS mode with the hostname field unset on port 443, the server starts and functions normally on https://localhost/
  2. If I start Bun.serve() in HTTPS mode with the hostname field set on port 443, I get error EADDRINUSE: Failed to start server. Is port 443 in use? (nothing is running on the port)
  3. If I immediately try step 1 again, it functions correctly.

Interestingly, if I follow similar steps on HTTP I get a similar error:

  1. If I start Bun.serve() in HTTP mode with the hostname field unset on port 80, the server starts and functions normally on http://localhost/
  2. If I start Bun.serve() in HTTP mode with the hostname field set on port 80, I get error EADDRINUSE: Failed to start server. Is port 80 in use? (nothing is running on the port)
  3. If I immediately try step 4 again, it functions correctly.

What is the expected behavior?

Bun.serve() starts correctly on each corresponding default port (server.url.href):

  • HTTPS: https://example.com/
  • HTTP: http://example.com/

What do you see instead?

  • HTTPS: EADDRINUSE: Failed to start server. Is port 443 in use?
  • HTTP: EADDRINUSE: Failed to start server. Is port 80 in use?

As steps 3 and 6 show, nothing is running on those ports.

Additional information

SNI was used to match the hostname value and certificate hostname for the HTTPS case

mangs avatar Apr 21 '24 16:04 mangs