Skip to content

feat: warn when ddev-router's ports don't answer on the host - #8990

Merged
rfay merged 3 commits into
mainfrom
20261020_rfay_router_port_check
Oct 21, 2026
Merged

rfay merged 3 commits into
mainfrom
20261020_rfay_router_port_check

Conversation

@rfay

@rfay rfay commented Oct 20, 2026

Copy link
Copy Markdown
Member

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:

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

Co-Authored-By: Claude Opus 5.5 [email protected]

@rfay
rfay requested review from a team as code owners October 20, 2026 19:07
@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Download this PR's build for your OS and architecture with:

ddev utility download-ddev --pr 8990

Or download the artifact for your OS and architecture directly:

See Testing a PR.

Open in GitHub Codespaces

@stasadev stasadev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread pkg/ddevapp/router.go
}
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, ", "))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
})

Comment thread pkg/netutil/netutil.go
return false
}
// Windows reports WSAECONNREFUSED (10061) rather than ECONNREFUSED.
return errors.Is(err, syscall.ECONNREFUSED) || errors.Is(err, syscall.Errno(10061))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@stasadev
stasadev self-requested a review October 20, 2026 21:11
rfay added a commit that referenced this pull request Oct 20, 2026
…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]>
@rfay

rfay commented Oct 20, 2026

Copy link
Copy Markdown
Member Author

Implemented those, thanks!

rfay and others added 2 commits October 20, 2026 21:18
## 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]>
@rfay
rfay force-pushed the 20261020_rfay_router_port_check branch from 06cc693 to 058b52b Compare October 21, 2026 03:18

@stasadev stasadev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread pkg/ddevapp/router.go Outdated
wait = nil
return fmt.Errorf("ddev-router failed to become ready after %.1fs; log=%s, err=%v", elapsed.Seconds(), logOutput, err)
}
warnUnreachableRouterPorts()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>
@rfay

rfay commented Oct 21, 2026

Copy link
Copy Markdown
Member Author

Fixed that

@stasadev stasadev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@rfay
rfay merged commit 18c58bf into main Oct 21, 2026
42 of 51 checks passed
@rfay
rfay deleted the 20261020_rfay_router_port_check branch October 21, 2026 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants