Repository navigation
feat: warn when ddev-router's ports don't answer on the host - #8990
Conversation
|
Download this PR's build for your OS and architecture with: ddev utility download-ddev --pr 8990Or download the artifact for your OS and architecture directly:
See Testing a PR. |
stasadev
left a comment
There was a problem hiding this comment.
Claude Code ran ddev start against a Docker-in-Docker daemon on tcp://127.0.0.1, where the router ports are published inside the container and not on the host. The PR build shows the new warning, and the base build says the project started while curl gets nothing. No false warning on rootful Docker, rootless Docker and rootless Podman.
A few small things inline.
🤖 Reviewed with assistance from Claude Code
| } | ||
| time.Sleep(500 * time.Millisecond) | ||
| } | ||
| util.Warning("%s is running, but nothing answers on host port(s) %s, so projects may not be reachable there. Your Docker provider may not be forwarding them; see https://docs.ddev.com/en/stable/users/usage/troubleshooting/#router-ports-not-reachable", nodeps.RouterContainer, strings.Join(refused, ", ")) |
There was a problem hiding this comment.
The ports are sorted as strings, so the warning looks like this:
nothing answers on host port(s) 10999, 443, 80, 8025, 8026, 8142, 8143
Maybe sort them as numbers before joining?
slices.SortFunc(refused, func(a, b string) int {
x, _ := strconv.Atoi(a)
y, _ := strconv.Atoi(b)
return cmp.Compare(x, y)
})| return false | ||
| } | ||
| // Windows reports WSAECONNREFUSED (10061) rather than ECONNREFUSED. | ||
| return errors.Is(err, syscall.ECONNREFUSED) || errors.Is(err, syscall.Errno(10061)) |
There was a problem hiding this comment.
IsPortActive above has its own ECONNREFUSED/WSAECONNREFUSED check. Maybe move this line into a small helper like isConnRefused(err) and use it in both places?
|
|
||
| If `ddev start` warns that nothing answers on the router's host ports, the router is running but your Docker provider isn't forwarding its ports to your computer. Restarting the Docker provider often fixes it. | ||
|
|
||
| With Lima or Colima on Linux, ports below 1024, such as 80 and 443, can't be forwarded unless your system allows it. Either allow them with `echo 'net.ipv4.ip_unprivileged_port_start=80' | sudo tee /etc/sysctl.d/99-unprivileged-ports.conf && sudo sysctl --system` and restart Lima or Colima, or move the router to higher ports with `ddev config global --router-http-port=8080 --router-https-port=8443`. |
There was a problem hiding this comment.
docker-installation.md sets the same thing with /etc/sysctl.d/60-rootless.conf and ip_unprivileged_port_start=0. Maybe use the same file and value here, so people don't end up with two files that set it differently?
…ion check [skip buildkite] Review follow-ups for #8990: GetBoundHostPorts sorted ports as strings, so the warning listed 10999 before 80. IsPortActive and IsPortRefused now share isConnRefused. The troubleshooting sysctl now uses the same file and value as docker-installation.md. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Implemented those, thanks! |
## Short Summary (TL;DR) After the router starts and is healthy, `ddev start` now checks that the router's published ports answer on the host, and warns when one refuses connections, so a provider that quietly fails to forward a port no longer looks like a successful start. ## The Issue While testing #8963 with Colima and Lima on Linux, `ddev start` succeeded and the router was healthy, but the project URL didn't answer. Lima forwards published ports to the host with `ssh -L` as the user, and Linux doesn't let users bind ports below `net.ipv4.ip_unprivileged_port_start` (1024 by default), so ports 80 and 443 failed. Lima logged it as "negligible", and nothing told the user. DDEV checks before starting that the ports are free, and the router's health check runs inside the container, so nothing checked that the ports answer on the host. ## How This PR Solves The Issue - `netutil.IsPortRefused()` reports whether a connection to a port on a loopback Docker IP is actively refused. Timeouts, non-loopback Docker hosts, and other errors count as "not refused", so remote Docker, WSL2 mirrored-mode timeouts, and security software that accepts every connection can't cause a false warning. - After a freshly started router becomes healthy, `warnUnreachableRouterPorts()` dials each published host port, retrying for up to 5 seconds because Lima sets up forwards shortly after the container starts. It warns, rather than failing, since the router itself is fine. - A new troubleshooting section, "Router Ports Not Reachable", covers the warning and the Lima and Colima fix. This is a general check, not one aimed at Lima: any provider whose port forwarding fails after the container starts now gets reported. ## Manual Testing Instructions On Linux with Lima or Colima (with KVM), a router port below `net.ipv4.ip_unprivileged_port_start` reproduces it: ```bash ddev utility download-ddev --pr 8990 export PATH="$HOME/tmp/ddev-download-ddev/pr-8990:$PATH" sysctl net.ipv4.ip_unprivileged_port_start # 1024 by default ddev config global --router-http-port=79 --router-https-port=442 ddev start # Expect: "ddev-router is running, but nothing answers on host port(s) 79, 442 ..." ddev poweroff ddev config global --router-http-port=80 --router-https-port=443 ``` On any supported provider, `ddev start` should show no new warning. See https://ddev--8990.org.readthedocs.build/en/8990/users/usage/troubleshooting/#router-ports-not-reachable ## Automated Testing Overview `TestIsPortRefused` checks a listening port and the same port after it closes. The check runs on every router start in the existing integration tests, so a false warning on any CI provider would show up in their output. 🤖 Developed with assistance from [Claude Code](https://claude.ai/code) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ion check [skip buildkite] Review follow-ups for #8990: GetBoundHostPorts sorted ports as strings, so the warning listed 10999 before 80. IsPortActive and IsPortRefused now share isConnRefused. The troubleshooting sysctl now uses the same file and value as docker-installation.md. Co-Authored-By: Claude Opus 5.5 <[email protected]>
06cc693 to
058b52b
Compare
stasadev
left a comment
There was a problem hiding this comment.
Thanks, the three earlier points are fixed. Claude Code ran it again on the same Docker-in-Docker setup, the warning shows up and the ports are sorted. One small thing inline about where the warning is printed.
| wait = nil | ||
| return fmt.Errorf("ddev-router failed to become ready after %.1fs; log=%s, err=%v", elapsed.Seconds(), logOutput, err) | ||
| } | ||
| warnUnreachableRouterPorts() |
There was a problem hiding this comment.
After the rebase on #8953 this runs while the "Waiting for ddev-router to become ready..." line is still open, so the warning lands in the middle of it, and the 5 seconds of retries count as router startup time:
Waiting for ddev-router to become ready...ddev-router is running, but nothing answers on host port(s) 28025, 28026, 28080, 28443, 28999, so projects may not be reachable there. ...
ready in 6.1s
Maybe call it after wait.Done(nil, "ready")?
wait.Done(nil, "ready")
wait = nil
if needsRecreation {
warnUnreachableRouterPorts()
}🤖 Reviewed with assistance from Claude Code
The port check ran while the "Waiting for ddev-router to become ready" line was still open. Its warning landed in the middle of that line, and its retries counted as router startup time. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Fixed that |
Short Summary (TL;DR)
After the router starts and is healthy,
ddev startnow checks that the router's published ports answer on the host, and warns when one refuses connections, so a provider that quietly fails to forward a port no longer looks like a successful start.The Issue
While testing #8963 with Colima and Lima on Linux,
ddev startsucceeded and the router was healthy, but the project URL didn't answer. Lima forwards published ports to the host withssh -Las the user, and Linux doesn't let users bind ports belownet.ipv4.ip_unprivileged_port_start(1024 by default), so ports 80 and 443 failed. Lima logged it as "negligible", and nothing told the user. DDEV checks before starting that the ports are free, and the router's health check runs inside the container, so nothing checked that the ports answer on the host.How This PR Solves The Issue
netutil.IsPortRefused()reports whether a connection to a port on a loopback Docker IP is actively refused. Timeouts, non-loopback Docker hosts, and other errors count as "not refused", so remote Docker, WSL2 mirrored-mode timeouts, and security software that accepts every connection can't cause a false warning.warnUnreachableRouterPorts()dials each published host port, retrying for up to 5 seconds because Lima sets up forwards shortly after the container starts. It warns, rather than failing, since the router itself is fine.This is a general check, not one aimed at Lima: any provider whose port forwarding fails after the container starts now gets reported.
Manual Testing Instructions
On Linux with Lima or Colima (with KVM), a router port below
net.ipv4.ip_unprivileged_port_startreproduces it:On any supported provider,
ddev startshould show no new warning. See https://ddev--8990.org.readthedocs.build/en/8990/users/usage/troubleshooting/#router-ports-not-reachableAutomated Testing Overview
TestIsPortRefusedchecks a listening port and the same port after it closes. The check runs on every router start in the existing integration tests, so a false warning on any CI provider would show up in their output.🤖 Developed with assistance from Claude Code
Co-Authored-By: Claude Opus 5.5 [email protected]