Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caddy is not throwing an error on MacOS if address is already in use #6515

Open
fschoell opened this issue Aug 12, 2024 · 1 comment
Open

Comments

@fschoell
Copy link

Caddy starts up without issues on MacOS even if there is already another process listening on the same port.

Example:

# test1/Caddyfile
:80 {
  respond "hello world server1"
}
# test2/Caddyfile
:80 {
  respond "hello world server2"
}

Starting up server 1:

$ caddy run --config test1/Caddyfile
2024/08/12 11:58:43.773	INFO	using config from file	{"file": "test1/Caddyfile"}
2024/08/12 11:58:43.773	INFO	adapted config to JSON	{"adapter": "caddyfile"}
2024/08/12 11:58:43.775	INFO	admin	admin endpoint started	{"address": "localhost:2019", "enforce_origin": false, "origins": ["//[::1]:2019", "//127.0.0.1:2019", "//localhost:2019"]}
2024/08/12 11:58:43.775	WARN	http.auto_https	server is listening only on the HTTP port, so no automatic HTTPS will be applied to this server	{"server_name": "srv0", "http_port": 80}
2024/08/12 11:58:43.775	INFO	tls.cache.maintenance	started background certificate maintenance	{"cache": "0xc000676280"}
2024/08/12 11:58:43.775	INFO	http.log	server running	{"name": "srv0", "protocols": ["h1", "h2", "h3"]}
2024/08/12 11:58:43.775	INFO	autosaved config (load with --resume flag)	{"file": "/Users/work/Library/Application Support/Caddy/autosave.json"}
2024/08/12 11:58:43.775	INFO	serving initial configuration
2024/08/12 11:58:43.799	INFO	tls	storage cleaning happened too recently; skipping for now	{"storage": "FileStorage:/Users/work/Library/Application Support/Caddy", "instance": "394620b5-a9e0-4018-b6c0-60875ef7ed91", "try_again": "2024/08/13 11:58:43.799", "try_again_in": 86399.999999331}
2024/08/12 11:58:43.800	INFO	tls	finished cleaning storage units

Starting up server 2:

$ caddy run --config test2/Caddyfile
2024/08/12 11:59:44.663	INFO	using config from file	{"file": "test2/Caddyfile"}
2024/08/12 11:59:44.664	INFO	adapted config to JSON	{"adapter": "caddyfile"}
2024/08/12 11:59:44.665	INFO	admin	admin endpoint started	{"address": "localhost:2019", "enforce_origin": false, "origins": ["//localhost:2019", "//[::1]:2019", "//127.0.0.1:2019"]}
2024/08/12 11:59:44.665	WARN	http.auto_https	server is listening only on the HTTP port, so no automatic HTTPS will be applied to this server	{"server_name": "srv0", "http_port": 80}
2024/08/12 11:59:44.665	INFO	tls.cache.maintenance	started background certificate maintenance	{"cache": "0xc00068b780"}
2024/08/12 11:59:44.665	INFO	http.log	server running	{"name": "srv0", "protocols": ["h1", "h2", "h3"]}
2024/08/12 11:59:44.665	INFO	autosaved config (load with --resume flag)	{"file": "/Users/work/Library/Application Support/Caddy/autosave.json"}
2024/08/12 11:59:44.665	INFO	serving initial configuration
2024/08/12 11:59:44.687	INFO	tls	storage cleaning happened too recently; skipping for now	{"storage": "FileStorage:/Users/work/Library/Application Support/Caddy", "instance": "394620b5-a9e0-4018-b6c0-60875ef7ed91", "try_again": "2024/08/13 11:59:44.687", "try_again_in": 86399.999999446}
2024/08/12 11:59:44.687	INFO	tls	finished cleaning storage units

Sending a request is answered by server 1:

$ curl http://localhost
hello world server1%

Expected behaviour: Server 2 should not start up but throw an error, such as it does on Linux systems:

$ caddy run --config test2/Caddyfile
2024/08/12 11:56:25.354	INFO	using config from file	{"file": "test1/Caddyfile"}
2024/08/12 11:56:25.355	INFO	adapted config to JSON	{"adapter": "caddyfile"}
2024/08/12 11:56:25.356	INFO	admin	admin endpoint started	{"address": ":2020", "enforce_origin": false, "origins": ["//:2020"]}
2024/08/12 11:56:25.356	WARN	admin	admin endpoint on open interface; host checking disabled	{"address": ":2020"}
2024/08/12 11:56:25.356	WARN	http.auto_https	server is listening only on the HTTP port, so no automatic HTTPS will be applied to this server	{"server_name": "srv0", "http_port": 80}
2024/08/12 11:56:25.356	INFO	tls.cache.maintenance	started background certificate maintenance	{"cache": "0xc00072be80"}
2024/08/12 11:56:25.356	INFO	tls.cache.maintenance	stopped background certificate maintenance	{"cache": "0xc00072be80"}
Error: loading initial config: loading new config: http app module: start: listening on :80: listen tcp :80: bind: address already in use

Versions:

$  caddy --version
v2.8.4 h1:q3pe0wpBj1OcHFZ3n/1nl4V4bxBrYoSoab7rL9BMYNk=

MacOS: 14.6.1

@mholt
Copy link
Member

mholt commented Aug 12, 2024

I've noticed that quirk about macOS. Kinda weird/cool I guess! It also doesn't require privileges to bind lower ports.

Not sure that this is a Caddy issue. 🤷‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants