bun
bun copied to clipboard
`Bun.serve()` combination of `hostname` and default port causes error on HTTP and HTTPS
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
to0.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).
- If I start
Bun.serve()
in HTTPS mode with thehostname
field unset on port 443, the server starts and functions normally onhttps://localhost/
- If I start
Bun.serve()
in HTTPS mode with thehostname
field set on port 443, I get errorEADDRINUSE: Failed to start server. Is port 443 in use?
(nothing is running on the port) - If I immediately try step 1 again, it functions correctly.
Interestingly, if I follow similar steps on HTTP I get a similar error:
- If I start
Bun.serve()
in HTTP mode with thehostname
field unset on port 80, the server starts and functions normally onhttp://localhost/
- If I start
Bun.serve()
in HTTP mode with thehostname
field set on port 80, I get errorEADDRINUSE: Failed to start server. Is port 80 in use?
(nothing is running on the port) - 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