peterldowns / localias

custom local domain aliases for local dev servers
MIT License
583 stars 3 forks source link

Error: failed to start mDNS server #20

Closed baryla closed 6 months ago

baryla commented 6 months ago

When running localias with localias run, I'm getting an error that mDNS server cannot be started;

failed to start mDNS server:
could not determine host IP for .local domains: lookup Adrians-Macbook-Pro.local.local: no such host

When running $ hostname (on MacOS Sonoma 14.2.1), I'm getting in terminal: Adrians-Macbook-Pro.local.

I suspect the issue is from this line where it assumes that local is not already passed in: https://github.com/peterldowns/localias/blob/e3fade1a3997fa5fe71d2db3d9801d1388c0d0f4/pkg/server/mdns.go#L46

I'd post a PR to only append .local if it doesn't already exist in the string but I'm not familiar with golang enough to contribute. Perhaps something like this could work:

userHost := baseHost

if strings.Contains(userHost, ".local") == false {
  userHost = userHost + ".local"
}

baseIPs, err := net.LookupIP(userHost)
peterldowns commented 6 months ago

Thanks for the bug report, and I’m sorry for the trouble. I’ll repro and fix sometime this week. This is probably affecting other people too, thank you again.

Just to help me debug, can you tell me what version of localias you’re running with localias version?

baryla commented 6 months ago

No worries at all. Thanks for taking the time to help and build this tool!

The version is: 2.0.1+commit.c358250. I only just installed it via brew yesterday.

peterldowns commented 6 months ago

^ I didn't mean to close this automatically, but I believe the issue is now fixed. I'm in the process of pushing up the new version to brew; I'll follow up here once you can upgrade and test to see if it fixes your problem.

peterldowns commented 6 months ago

@baryla if you brew upgrade localias, you should receive localias version 2.0.2+commit.56d660e, and it should correctly start the mDNS server. Please confirm, and if it works, close the issue. 🫡

taylorthurlow commented 6 months ago

@peterldowns I just closed #21, and I know I neglected to show you the log output, but I also had this issue and can confirm the new release has fixed the extra .local problem. Or at the very least, I see no error message anymore.

peterldowns commented 6 months ago

@taylorthurlow OK, based on your confirmation that you did indeed have this same problem, I'm going to mark this issue as closed.

@baryla if for some reason the fix didn't work for you, please re-open this issue.

distinctgrey commented 6 months ago

@peterldowns just installed localias, and I encounter exactly this issue.

Versions:

Terminal output:

➜ localias list
sveltekit.local -> 5173

~ 
➜ localias -v
2.0.2+commit.56d660e

~ 
➜ localias run
2024/03/20 22:28:25.076 INFO    admin   admin endpoint started  {"address": "localhost:2019", "enforce_origin": false, "origins": ["//127.0.0.1:2019", "//localhost:2019", "//[::1]:2019"]}
2024/03/20 22:28:25.076 INFO    tls.cache.maintenance   started background certificate maintenance      {"cache": "0x1400037b260"}
2024/03/20 22:28:25.077 INFO    http    server is listening only on the HTTPS port but has no TLS connection policies; adding one to enable TLS {"server_name": "srv0", "https_port": 443}
2024/03/20 22:28:25.077 INFO    http    enabling automatic HTTP->HTTPS redirects        {"server_name": "srv0"}
2024/03/20 22:28:25.082 INFO    pki.ca.local    root certificate is already trusted by system   {"path": "storage:pki/authorities/local/root.crt"}
2024/03/20 22:28:25.082 INFO    tls     cleaning storage unit   {"description": "FileStorage:/Users/thomas/Library/Application Support/localias/caddy"}
2024/03/20 22:28:25.082 INFO    http    enabling HTTP/3 listener        {"addr": ":443"}
2024/03/20 22:28:25.082 INFO    http.log        server running  {"name": "srv0", "protocols": ["h1", "h2", "h3"]}
2024/03/20 22:28:25.082 INFO    http.log        server running  {"name": "remaining_auto_https_redirects", "protocols": ["h1", "h2", "h3"]}
2024/03/20 22:28:25.082 INFO    http    enabling automatic TLS certificate management   {"domains": ["sveltekit.local"]}
2024/03/20 22:28:25.082 INFO    tls     finished cleaning storage units
failed to start mDNS server:
could not determine host IP for .local domains: lookup thdg_mbp.local: no such host
daemon: listening for rpc requests
peterldowns commented 6 months ago

@distinctgrey very weird, I haven't seen this failure where the current host cannot be found over mdns. Can you try killing any mdnsresponder processes with kill -9 and trying again?

# show existing processes
ps aux | grep -i mDNSResponder
# kill
sudo pkill -9 mDNSResponder
# confirm that the process restarted successfully, has a new pid
ps aux | grep -i mDNSResponder

I'm not on macOS 14, and unfortunately I can't reproduce this problem. Is there any way in which you know you're doing something weird with your /etc/hosts or /etc/resolv.conf or your network settings? Is it possible you're connected to a corporate VPN of some sort?

I'm grasping at straws, sorry, I really don't know what's wrong here. I'll push a "fix" that turns this into a clearer warning, and explains that without the dns server requests to *.local will be subject to macOS-induced delays like I wrote above.

peterldowns commented 4 months ago

@distinctgrey did restarting mDNSResponder fix the problem? Do you have any more information you can share about your networking setup? If you run hostname, what is the output?