Skip to content

fix(router): Prevent unnecessary router re-creation when bound ports unchanged, fixes #6703 - #7992

Merged
rfay merged 24 commits into
mainfrom
copilot/fix-router-recreation-issue
Jan 7, 2026
Merged

rfay merged 24 commits into
mainfrom
copilot/fix-router-recreation-issue

Conversation

Copilot AI commented Dec 30, 2025 •

Copy link
Copy Markdown
Contributor

The Issue

The router container was being recreated on every project start, even when exposed ports hadn't changed. This caused unnecessary delays and Docker churn, particularly noticeable when starting a third or fourth project.

How This PR Solves The Issue

Modified StartDdevRouter() to check if the router is already running with the correct port configuration. The router is now only recreated when:

  • Ports have changed, OR
  • Router is not running/healthy
  • Router is NOT stopped when last project is stopped (Behavior change)

Manual Testing Instructions

  1. Start 3-4 DDEV projects with default ports (80, 443)
  2. Stop one project: ddev stop project3
  3. Start it again: ddev start project3
  4. Expected: Router should NOT be recreated (no "Container ddev-router Recreate" message)
  5. Verify: Check debug output with DDEV_DEBUG=true ddev start project3 - should see "Router ports have not changed, skipping recreation"

To test port changes work correctly:

  1. Add a project with custom port: router_http_port: 8080
  2. Start the project: ddev start project-custom-port
  3. Expected: Router SHOULD be recreated to bind new port
  • ddev stop -a and then check router status
  • ddev start a project and router should already be waiting to go and not be recreated unless ports change.

Automated Testing Overview

Added TestPortsMatch function in pkg/ddevapp/router_test.go that validates the port comparison logic with 6 test cases:

  • Empty slices match
  • Same ports match
  • Same ports in different order match
  • Different ports don't match
  • Different lengths don't match
  • Subsets don't match

Existing router tests continue to validate overall router functionality.

Release/Deployment Notes

  • Backward compatible: No breaking changes, existing behavior preserved
  • Performance improvement: Significant speed improvement for starting 3+ projects with same ports
  • Test suite impact: Should see notable performance improvements in CI/tests that start multiple projects
  • Debug output: Added helpful messages for troubleshooting router behavior

Technical Details

Files changed:

  • pkg/ddevapp/router.go (+73/-18 lines)
  • pkg/ddevapp/router_test.go (+54 lines)

Before: Starting dcmsolivero (4th project, same ports)

Starting ddev-router if necessary...
 Container ddev-router  Recreate 
 Container ddev-router  Recreated

After: Starting dcmsolivero (4th project, same ports)

Starting ddev-router if necessary...
(router already healthy, skips recreation)
Original prompt

This section details on the original issue you should resolve

<issue_title>router gets recreated on start of a third+ project without the need to support new ports</issue_title>
<issue_description>### Preliminary checklist

Output of ddev utility test or ddev utility diagnose

Expand `ddev utility diagnose` diagnostic information
Environment
===========
ℹ DDEV version: v1.24.10-106-g0a844d428
ℹ OS: Darwin arm64
ℹ Shell: /bin/zsh
ℹ Docker provider: lima-rootless
ℹ Docker version: 29.1.3

Docker Environment
==================
✓ Docker is running
✓ Docker disk space: 80% used
✓ Can run containers with volume mounts
✓ Internet access from containers
✓ Docker buildx working
✓ Docker authentication configured

Network Connectivity
====================
✓ Internet accessible from host
✓ DNS resolves *.ddev.site

HTTPS/mkcert
============
✓ mkcert is installed: v1.4.4
✓ mkcert CA certificates exist

Current Project
===============
ℹ Name: dcmsolivero
ℹ Type: drupal11
ℹ Status: running
✓ No custom configurations detected
✓ Project containers are responsive
✓ HTTP access working: http://dcmsolivero.ddev.site

Summary
=======

✓ All checks passed! DDEV should work correctly.

Expected Behavior

i would expect that on project start the router would not have to be created on every project start. i would expect that on some project starts only the projects web and db containers are getting created and not also the router again.

Actual Behavior

i had four running projects:

$> ddev list
┌─────────────┬──────────────┬─────────────────────┬───────────────────────────────┬──────────┐
│ NAME        │ STATUS       │ LOCATION            │ URL                           │ TYPE     │
├─────────────┼──────────────┼─────────────────────┼───────────────────────────────┼──────────┤
│ core        │ running (ok) │ ~/Sites/core        │ https://core.ddev.site        │ drupal11 │
├─────────────┼──────────────┼─────────────────────┼───────────────────────────────┼──────────┤
│ dcms        │ running (ok) │ ~/Sites/dcms        │ https://dcms.ddev.site        │ drupal11 │
├─────────────┼──────────────┼─────────────────────┼───────────────────────────────┼──────────┤
│ dcmsolivero │ running (ok) │ ~/Sites/dcmsolivero │ https://dcmsolivero.ddev.site │ drupal11 │
├─────────────┼──────────────┼─────────────────────┼───────────────────────────────┼──────────┤
│ frankenphp  │ running (ok) │ ~/Sites/frankenphp  │ https://frankenphp.ddev.site  │ drupal11 │
├─────────────┼──────────────┼─────────────────────┼───────────────────────────────┼──────────┤
│ nocodb      │ stopped      │ ~/Sites/nocodb      │                               │ php      │
├─────────────┼──────────────┼─────────────────────┼───────────────────────────────┼──────────┤
│ uisuite     │ stopped      │ ~/Sites/uisuite     │                               │ drupal11 │
├─────────────┼──────────────┼─────────────────────┼───────────────────────────────┼──────────┤
│ Router      │ OK           │ ~/.ddev             │ http://127.0.0.1:10999        │          │
└─────────────┴──────────────┴─────────────────────┴───────────────────────────────┴──────────┘

dcms and dcmsolivero are identical installs of drupal cms 2.x. dcmsoliver is basically the database of dcms exported, then the folder with the exported database cloned, within the cloned folder ddev config ran again to add a new project name. so both projects are identical except the name and no additional service added. when i stop dcmsoliver:

$> ddev stop dcmsolivero 
 Container ddev-dcmsolivero-db  Stopped 
 Container ddev-dcmsolivero-web  Stopped 
 Container ddev-dcmsolivero-db  Stopped 
 Container ddev-dcmsolivero-web  Stopped 
 Container ddev-dcmsolivero-db  Removed 
 Container ddev-dcmsolivero-web  Removed 
 Network ddev-dcmsolivero_default  Removed 
Project dcmsolivero has been stopped. 

and when i start it again the router is getting recreated.

$> ddev start dcmsolivero
Starting dcmsolivero... 
Building project images....
Project images built in 1s. 
 Network ddev-dcmsolivero_default  Created 
 Container ddev-dcmsolivero-web  Created 
 Container ddev-dcmsolivero-db  Created 
 Container ddev-dcmsolivero-db  Started 
 Container ddev-dcmsolivero-web  Started 
Starting Mutagen sync process....
Mutagen sync flush completed in 2s.
For details on sync status 'ddev mutagen st dcmsolivero -l' 
Waiting for containers to become ready: [web db] 
Starting ddev-router if necessary... 
 Container ddev-router  Recreate 
 Containe...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes ddev/ddev#7989

<!-- START COPILOT CODING AGENT TIPS -->
---

✨ Let Copilot coding agent [set things up for you](https://github.com/ddev/ddev/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix router recreation on start of third project Prevent unnecessary router recreation when ports unchanged Dec 30, 2025
Copilot AI requested a review from rfay December 30, 2025 14:46
@rfay

rfay commented Dec 30, 2025

Copy link
Copy Markdown
Member

@copilot you forgot make staticrequired, fix the gofmt failures. gofmt -w

Then update the OP to use the format in .github/PULL_REQUEST_TEMPLATE.md. You can keep your extensive comments at the bottom.

And use the correct format for the PR title: fix(router): ...

Copilot AI commented Dec 30, 2025

Copy link
Copy Markdown
Contributor Author

@copilot you forgot make staticrequired, fix the gofmt failures. gofmt -w

Then update the OP to use the format in .github/PULL_REQUEST_TEMPLATE.md. You can keep your extensive comments at...

Fixed gofmt issues in commit 5a2a091. Updated PR description to follow the template format.

Note: The PR title needs to be updated to fix(router): prevent unnecessary recreation when ports unchanged - this requires repository permissions to edit the PR title directly.

@rfay rfay changed the title Prevent unnecessary router recreation when ports unchanged fix(router): Prevent unnecessary router recreation when bound ports unchanged Dec 30, 2025
@rfay rfay changed the title fix(router): Prevent unnecessary router recreation when bound ports unchanged fix(router): Prevent unnecessary router re-creation when bound ports unchanged Dec 31, 2025
@github-actions

github-actions Bot commented Dec 31, 2025 •

Copy link
Copy Markdown

@rfay
rfay force-pushed the copilot/fix-router-recreation-issue branch from 08d1c23 to f65c560 Compare December 31, 2025 23:41
@rfay

rfay commented Jan 1, 2026

Copy link
Copy Markdown
Member

I looked at the failures of the quickstart, and I think this one needs to wait until the ddev-router healthcheck PRs go in. It also may be that we have to have a special healthcheck check for the router when we are not even starting it.

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

I think this may work. Code looks OK and it's closer all the time to testing successfully.

@rfay
rfay force-pushed the copilot/fix-router-recreation-issue branch from 10c4d22 to 30f1652 Compare January 3, 2026 17:19
@rfay

rfay commented Jan 3, 2026

Copy link
Copy Markdown
Member

That experimental approach did not work. Now trying just removing the special lima port-wait, which is likely the reason that we haven't seen this in other contexts with docker 29.

@rfay rfay changed the title fix(router): Prevent unnecessary router re-creation when bound ports unchanged fix(router): EXPERIMENT: Stop waiting for bound ports in Lima-related docker providers Jan 3, 2026
@rfay rfay changed the title fix(router): EXPERIMENT: Stop waiting for bound ports in Lima-related docker providers fix(router): Prevent unnecessary router re-creation when bound ports unchanged Jan 3, 2026
@rfay
rfay marked this pull request as ready for review January 3, 2026 23:16
@rfay
rfay requested review from a team as code owners January 3, 2026 23:16
@rfay
rfay requested a review from stasadev January 3, 2026 23:17
@rfay
rfay force-pushed the copilot/fix-router-recreation-issue branch from 637c85e to c4ff4dd Compare January 4, 2026 14:21

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

It seems to fix this issue (without adding any new global config):


Interesting side effect with ephemeral ports:

docker run --rm -p 80:80 -p 443:443 nginx

$ ddev start
Port 80 is busy, using 33000 instead, see https://ddev.com/s/port-conflict 
Port 443 is busy, using 33001 instead, see https://ddev.com/s/port-conflict

$ ddev restart 
Port 80 is busy, using 33002 instead, see https://ddev.com/s/port-conflict 
Port 443 is busy, using 33003 instead, see https://ddev.com/s/port-conflict

$ ddev restart
Port 80 is busy, using 33000 instead, see https://ddev.com/s/port-conflict 
Port 443 is busy, using 33001 instead, see https://ddev.com/s/port-conflict

So ddev-router doesn't reuse 33000/33001 for primary router ports, when it's already in use by ddev-router.


Comment thread docs/tests/backdrop.bats Resolved
Comment thread pkg/ddevapp/poweroff.go Resolved
Comment thread pkg/ddevapp/router.go Resolved
rfay and others added 12 commits January 5, 2026 15:50
When the router is reused (not recreated because ports haven't changed),
we now force the healthcheck to run before returning from StartDdevRouter().
This ensures Traefik has loaded the new project's configuration.

The fix runs `rm -f /tmp/healthy && /healthcheck.sh` in the router container:
- Removes /tmp/healthy so the healthcheck doesn't sleep 59 seconds
- Runs the healthcheck which waits for routers to load via wait_for_routers()
- Fails StartDdevRouter if the healthcheck fails

This fixes intermittent quickstart failures where projects couldn't be
accessed because Traefik hadn't loaded their routes yet.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@rfay rfay changed the title fix(router): Prevent unnecessary router re-creation when bound ports unchanged fix(router): Prevent unnecessary router re-creation when bound ports unchanged, fixes #6703 Jan 5, 2026
@rfay
rfay force-pushed the copilot/fix-router-recreation-issue branch from ac1b74b to 9ca91b9 Compare January 5, 2026 22:53
When ports 80/443 are busy, DDEV allocates ephemeral ports (e.g., 33000/33001).
Previously, on restart these ports appeared "busy" because the router itself
was using them, causing new ports to be allocated and forcing router recreation.

Now AllocateAvailablePortForRouter checks if the router already has a port
bound and reuses it instead of skipping to the next available port.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@rfay

rfay commented Jan 6, 2026 •

Copy link
Copy Markdown
Member

Thanks for noting the no-reuse-of-33000 problem @stasadev - I think I had seen that before, but it's good to get it fixed here, fixed in 25dddc5 (#7992)

@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 1263ece into main Jan 7, 2026
7 of 8 checks passed
@rfay
rfay deleted the copilot/fix-router-recreation-issue branch January 7, 2026 14:02
rfay added a commit to rfay/ddev that referenced this pull request Feb 11, 2026
…8110

## The Issue

- Fixes ddev#8110

When starting a second DDEV project with identical port configuration (e.g., both using ddev-adminer on port 9101), the router optimization from PR ddev#7992 prevented recreation because ports matched. However, network aliases in `.router-compose-full.yaml` (required by PR ddev#7642 for inter-container HTTP/S communication) were not updated. This caused the second project's containers to be unable to access their own services via HTTPS, breaking inter-container communication.

## How This PR Solves The Issue

This PR extends the router recreation logic to check both ports AND hostnames (network aliases), not just ports:

1. **Added `GetRouterNetworkAliases()`** in `pkg/dockerutil/containers.go` - Extracts network aliases from the running router container's `ddev_default` network configuration, mirroring the pattern of `GetBoundHostPorts()`

2. **Added `HostnamesMatch()`** in `pkg/ddevapp/router.go` - Compares existing vs needed hostnames using subset matching (allows extra hostnames from stopped projects), exactly mirroring `PortsMatch()` logic

3. **Modified `StartDdevRouter()`** in `pkg/ddevapp/router.go` - Now checks both ports and hostnames before deciding to skip recreation. The router is recreated when EITHER ports OR hostnames have changed, while preserving the optimization when neither has changed

The fix maintains the performance optimization from PR ddev#7992 (router isn't recreated unnecessarily) while ensuring network aliases are always updated when new projects start.

## Manual Testing Instructions

Test the exact reproduction scenario from issue ddev#8110:

```bash
# Clean slate
ddev poweroff
mkdir -p /tmp/pruebas && cd /tmp/pruebas

# Start first project with adminer
mkdir prueba1 && cd prueba1
ddev config --auto
ddev add-on get ddev/ddev-adminer
DDEV_DEBUG=true ddev start
# Verify works from container
ddev exec curl -I https://prueba1.ddev.site:9101
# Should succeed

# Start second project with same configuration
cd /tmp/pruebas
mkdir prueba2 && cd prueba2
ddev config --auto
ddev add-on get ddev/ddev-adminer
DDEV_DEBUG=true ddev start
# Should see: "Router hostnames have changed, will recreate router"
ddev exec curl -I https://prueba2.ddev.site:9101
# Should succeed (this would fail without the fix)

# Verify both aliases exist in router
docker inspect ddev-router --format '{{json .NetworkSettings.Networks.ddev_default.Aliases}}' | jq
# Should show both prueba1.ddev.site and prueba2.ddev.site

# Verify optimization still works
ddev restart
# Should see: "Router ports and hostnames have not changed, skipping recreation"
```

## Automated Testing Overview

**New Unit Tests:**
- `TestHostnamesMatch()` in `pkg/ddevapp/router_test.go` - 6 test cases verifying hostname comparison logic mirrors `TestPortsMatch()` behavior (empty slices, identical, different order, missing hostname, extra hostnames)
- `TestGetRouterNetworkAliases()` in `pkg/dockerutil/containers_test.go` - Verifies alias extraction from containers, error handling

**Integration Tests:**
- Existing `TestNetworkAliases()` in `pkg/dockerutil/networks_test.go` will verify the fix works end-to-end (can be enhanced with same-port scenario)

All tests pass. golangci-lint passes with 0 issues.

## Release/Deployment Notes

- **Backward compatible:** No breaking changes, existing behavior preserved
- **Performance:** Minimal impact - one additional Docker API call (`ContainerInspect` for network aliases) when router already exists, same O(n+m) complexity as port comparison
- **User impact:** Fixes broken inter-container communication for users with multiple projects using identical port configurations (common with add-ons)
- **No config changes required:** Fix works automatically on upgrade

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
rfay added a commit to rfay/ddev that referenced this pull request Feb 12, 2026
…8110

## The Issue

- Fixes ddev#8110

When starting a second DDEV project with identical port configuration (e.g., both using ddev-adminer on port 9101), the router optimization from PR ddev#7992 prevented recreation because ports matched. However, network aliases in `.router-compose-full.yaml` (required by PR ddev#7642 for inter-container HTTP/S communication) were not updated. This caused the second project's containers to be unable to access their own services via HTTPS, breaking inter-container communication.

## How This PR Solves The Issue

This PR extends the router recreation logic to check both ports AND hostnames (network aliases), not just ports:

1. **Added `GetRouterNetworkAliases()`** in `pkg/dockerutil/containers.go` - Extracts network aliases from the running router container's `ddev_default` network configuration, mirroring the pattern of `GetBoundHostPorts()`

2. **Added `HostnamesMatch()`** in `pkg/ddevapp/router.go` - Compares existing vs needed hostnames using subset matching (allows extra hostnames from stopped projects), exactly mirroring `PortsMatch()` logic

3. **Modified `StartDdevRouter()`** in `pkg/ddevapp/router.go` - Now checks both ports and hostnames before deciding to skip recreation. The router is recreated when EITHER ports OR hostnames have changed, while preserving the optimization when neither has changed

The fix maintains the performance optimization from PR ddev#7992 (router isn't recreated unnecessarily) while ensuring network aliases are always updated when new projects start.

## Manual Testing Instructions

Test the exact reproduction scenario from issue ddev#8110:

```bash
# Clean slate
ddev poweroff
mkdir -p /tmp/pruebas && cd /tmp/pruebas

# Start first project with adminer
mkdir prueba1 && cd prueba1
ddev config --auto
ddev add-on get ddev/ddev-adminer
DDEV_DEBUG=true ddev start
# Verify works from container
ddev exec curl -I https://prueba1.ddev.site:9101
# Should succeed

# Start second project with same configuration
cd /tmp/pruebas
mkdir prueba2 && cd prueba2
ddev config --auto
ddev add-on get ddev/ddev-adminer
DDEV_DEBUG=true ddev start
# Should see: "Router hostnames have changed, will recreate router"
ddev exec curl -I https://prueba2.ddev.site:9101
# Should succeed (this would fail without the fix)

# Verify both aliases exist in router
docker inspect ddev-router --format '{{json .NetworkSettings.Networks.ddev_default.Aliases}}' | jq
# Should show both prueba1.ddev.site and prueba2.ddev.site

# Verify optimization still works
ddev restart
# Should see: "Router ports and hostnames have not changed, skipping recreation"
```

## Automated Testing Overview

**New Unit Tests:**
- `TestHostnamesMatch()` in `pkg/ddevapp/router_test.go` - 6 test cases verifying hostname comparison logic mirrors `TestPortsMatch()` behavior (empty slices, identical, different order, missing hostname, extra hostnames)
- `TestGetRouterNetworkAliases()` in `pkg/dockerutil/containers_test.go` - Verifies alias extraction from containers, error handling

**Integration Tests:**
- Existing `TestNetworkAliases()` in `pkg/dockerutil/networks_test.go` will verify the fix works end-to-end (can be enhanced with same-port scenario)

All tests pass. golangci-lint passes with 0 issues.

## Release/Deployment Notes

- **Backward compatible:** No breaking changes, existing behavior preserved
- **Performance:** Minimal impact - one additional Docker API call (`ContainerInspect` for network aliases) when router already exists, same O(n+m) complexity as port comparison
- **User impact:** Fixes broken inter-container communication for users with multiple projects using identical port configurations (common with add-ons)
- **No config changes required:** Fix works automatically on upgrade

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
rfay added a commit to rfay/ddev that referenced this pull request Feb 17, 2026
…8110

## The Issue

- Fixes ddev#8110

When starting a second DDEV project with identical port configuration (e.g., both using ddev-adminer on port 9101), the router optimization from PR ddev#7992 prevented recreation because ports matched. However, network aliases in `.router-compose-full.yaml` (required by PR ddev#7642 for inter-container HTTP/S communication) were not updated. This caused the second project's containers to be unable to access their own services via HTTPS, breaking inter-container communication.

## How This PR Solves The Issue

This PR extends the router recreation logic to check both ports AND hostnames (network aliases), not just ports:

1. **Added `GetRouterNetworkAliases()`** in `pkg/dockerutil/containers.go` - Extracts network aliases from the running router container's `ddev_default` network configuration, mirroring the pattern of `GetBoundHostPorts()`

2. **Added `HostnamesMatch()`** in `pkg/ddevapp/router.go` - Compares existing vs needed hostnames using subset matching (allows extra hostnames from stopped projects), exactly mirroring `PortsMatch()` logic

3. **Modified `StartDdevRouter()`** in `pkg/ddevapp/router.go` - Now checks both ports and hostnames before deciding to skip recreation. The router is recreated when EITHER ports OR hostnames have changed, while preserving the optimization when neither has changed

The fix maintains the performance optimization from PR ddev#7992 (router isn't recreated unnecessarily) while ensuring network aliases are always updated when new projects start.

## Manual Testing Instructions

Test the exact reproduction scenario from issue ddev#8110:

```bash
# Clean slate
ddev poweroff
mkdir -p /tmp/pruebas && cd /tmp/pruebas

# Start first project with adminer
mkdir prueba1 && cd prueba1
ddev config --auto
ddev add-on get ddev/ddev-adminer
DDEV_DEBUG=true ddev start
# Verify works from container
ddev exec curl -I https://prueba1.ddev.site:9101
# Should succeed

# Start second project with same configuration
cd /tmp/pruebas
mkdir prueba2 && cd prueba2
ddev config --auto
ddev add-on get ddev/ddev-adminer
DDEV_DEBUG=true ddev start
# Should see: "Router hostnames have changed, will recreate router"
ddev exec curl -I https://prueba2.ddev.site:9101
# Should succeed (this would fail without the fix)

# Verify both aliases exist in router
docker inspect ddev-router --format '{{json .NetworkSettings.Networks.ddev_default.Aliases}}' | jq
# Should show both prueba1.ddev.site and prueba2.ddev.site

# Verify optimization still works
ddev restart
# Should see: "Router ports and hostnames have not changed, skipping recreation"
```

## Automated Testing Overview

**New Unit Tests:**
- `TestHostnamesMatch()` in `pkg/ddevapp/router_test.go` - 6 test cases verifying hostname comparison logic mirrors `TestPortsMatch()` behavior (empty slices, identical, different order, missing hostname, extra hostnames)
- `TestGetRouterNetworkAliases()` in `pkg/dockerutil/containers_test.go` - Verifies alias extraction from containers, error handling

**Integration Tests:**
- Existing `TestNetworkAliases()` in `pkg/dockerutil/networks_test.go` will verify the fix works end-to-end (can be enhanced with same-port scenario)

All tests pass. golangci-lint passes with 0 issues.

## Release/Deployment Notes

- **Backward compatible:** No breaking changes, existing behavior preserved
- **Performance:** Minimal impact - one additional Docker API call (`ContainerInspect` for network aliases) when router already exists, same O(n+m) complexity as port comparison
- **User impact:** Fixes broken inter-container communication for users with multiple projects using identical port configurations (common with add-ons)
- **No config changes required:** Fix works automatically on upgrade

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
rfay added a commit to rfay/ddev that referenced this pull request Feb 18, 2026
…8110

## The Issue

- Fixes ddev#8110

When starting a second DDEV project with identical port configuration (e.g., both using ddev-adminer on port 9101), the router optimization from PR ddev#7992 prevented recreation because ports matched. However, network aliases in `.router-compose-full.yaml` (required by PR ddev#7642 for inter-container HTTP/S communication) were not updated. This caused the second project's containers to be unable to access their own services via HTTPS, breaking inter-container communication.

## How This PR Solves The Issue

This PR extends the router recreation logic to check both ports AND hostnames (network aliases), not just ports:

1. **Added `GetRouterNetworkAliases()`** in `pkg/dockerutil/containers.go` - Extracts network aliases from the running router container's `ddev_default` network configuration, mirroring the pattern of `GetBoundHostPorts()`

2. **Added `HostnamesMatch()`** in `pkg/ddevapp/router.go` - Compares existing vs needed hostnames using subset matching (allows extra hostnames from stopped projects), exactly mirroring `PortsMatch()` logic

3. **Modified `StartDdevRouter()`** in `pkg/ddevapp/router.go` - Now checks both ports and hostnames before deciding to skip recreation. The router is recreated when EITHER ports OR hostnames have changed, while preserving the optimization when neither has changed

The fix maintains the performance optimization from PR ddev#7992 (router isn't recreated unnecessarily) while ensuring network aliases are always updated when new projects start.

## Manual Testing Instructions

Test the exact reproduction scenario from issue ddev#8110:

```bash
# Clean slate
ddev poweroff
mkdir -p /tmp/pruebas && cd /tmp/pruebas

# Start first project with adminer
mkdir prueba1 && cd prueba1
ddev config --auto
ddev add-on get ddev/ddev-adminer
DDEV_DEBUG=true ddev start
# Verify works from container
ddev exec curl -I https://prueba1.ddev.site:9101
# Should succeed

# Start second project with same configuration
cd /tmp/pruebas
mkdir prueba2 && cd prueba2
ddev config --auto
ddev add-on get ddev/ddev-adminer
DDEV_DEBUG=true ddev start
# Should see: "Router hostnames have changed, will recreate router"
ddev exec curl -I https://prueba2.ddev.site:9101
# Should succeed (this would fail without the fix)

# Verify both aliases exist in router
docker inspect ddev-router --format '{{json .NetworkSettings.Networks.ddev_default.Aliases}}' | jq
# Should show both prueba1.ddev.site and prueba2.ddev.site

# Verify optimization still works
ddev restart
# Should see: "Router ports and hostnames have not changed, skipping recreation"
```

## Automated Testing Overview

**New Unit Tests:**
- `TestHostnamesMatch()` in `pkg/ddevapp/router_test.go` - 6 test cases verifying hostname comparison logic mirrors `TestPortsMatch()` behavior (empty slices, identical, different order, missing hostname, extra hostnames)
- `TestGetRouterNetworkAliases()` in `pkg/dockerutil/containers_test.go` - Verifies alias extraction from containers, error handling

**Integration Tests:**
- Existing `TestNetworkAliases()` in `pkg/dockerutil/networks_test.go` will verify the fix works end-to-end (can be enhanced with same-port scenario)

All tests pass. golangci-lint passes with 0 issues.

## Release/Deployment Notes

- **Backward compatible:** No breaking changes, existing behavior preserved
- **Performance:** Minimal impact - one additional Docker API call (`ContainerInspect` for network aliases) when router already exists, same O(n+m) complexity as port comparison
- **User impact:** Fixes broken inter-container communication for users with multiple projects using identical port configurations (common with add-ons)
- **No config changes required:** Fix works automatically on upgrade

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
stasadev added a commit to stasadev/ddev that referenced this pull request Oct 7, 2026
…hand

## Short Summary (TL;DR)

The all-project-types job is the only CI job that runs tests with `GOTEST_SHORT` unset, and it ran a hand-kept list that had fallen behind, so 16 tests that skip or shrink under `GOTEST_SHORT` never ran in full anywhere. The list is now generated from the tests themselves, so it can't fall behind again.

## The Issue

Found while working on ddev#7904, which changes `TestDebugRebuildCmd`: CI logs show `--- SKIP: TestDebugRebuildCmd` in every job, because Buildkite and `test-reusable.yml` set `GOTEST_SHORT=16` and apache-fpm sets `5`.

The list came from ddev#6693 and broke in three ways:

- ddev#7027 renamed `TestComposerCreateCmd` to `TestComposerCreateProjectCmd`, so that entry has matched nothing since.
- ddev#8028 added `GOTEST_SHORT` skips to `TestDebugRebuildCmd`, `TestDdevImportDB`, `TestDdevRestoreSnapshot`, `TestProcessHooks`, and `TestWebserverMariaMySQLDBClient`, and later PRs did the same for `TestEphemeralPortsReusedOnRestart` (ddev#7992), `TestRouterPortSubstitutionPersistsAcrossProjects` (ddev#8653), `TestSnapshotUncompressed` (ddev#8704), `TestDebugDeleteVolumeCmd` (ddev#8756), and `TestDdevExportDB` (ddev#8798), none of them updating the list.
- `TestComposerVersionConfig`, `TestHttpsRedirection`, `TestMysqlCommand`, `TestDdevStartMultipleHostnames`, and `TestProjectAutocompletionForExecCmd` already did less under `GOTEST_SHORT` when ddev#6693 wrote the list, and weren't on it.

## How This PR Solves The Issue

Tests use three `testcommon` helpers instead of reading `GOTEST_SHORT`: `SkipIfGotestShort(t)`, `IsGotestShort(t)`, and `UsesAllTestSites(t)`, a marker for tests that loop over every test site. `.github/workflows/all-project-types-tests.sh` finds the tests that call them and prints the `-run` pattern, and fails if a test other than `TestMain` reads `GOTEST_SHORT` itself.

The pattern is anchored, so prefix matches such as every `TestCmdStart*` test or `TestAutocompleteServiceForServiceFlag` no longer ride along; like `TestAppdirAlreadyInUse` and `TestConfigValidate`, which also leave the list, they don't depend on `GOTEST_SHORT` and run in every job. The `GOTEST_SHORT` branches that ddev#8028 made unreachable in `TestComposerCreateProjectCmd` and `TestDdevAllDatabases` are removed.

## Manual Testing Instructions

```bash
.github/workflows/all-project-types-tests.sh
# Expect ^(TestAutocompletionForDescribeCmd|...|TestWriteDrushConfig)\b with the 42 tests below
```

Adding `if os.Getenv("GOTEST_SHORT") != "" { t.Skip() }` to any test makes the script print that file and line and exit non-zero.

## Automated Testing Overview

In the all-project-types job, the "Compute TESTARGS" step of `prepare-testargs` should print a `-run '^(...)\b'` pattern with exactly these 42 tests, and the test log should show each of them running, none skipped because of `GOTEST_SHORT`:

```text
TestAutocompletionForDescribeCmd TestAutocompletionForStartCmd TestAutocompletionForStopCmd
TestAvailableUpdates TestCmdDescribe TestCmdDescribeAppFunction TestCmdDescribeAppUsingSitename
TestCmdList TestCmdStart TestCmdStop TestComposerCreateProjectCmd TestComposerVersionConfig
TestConfigDatabaseVersion TestDdevAllDatabases TestDdevExportDB TestDdevFullSiteSetup
TestDdevImportDB TestDdevImportFiles TestDdevImportFilesCustomUploadDir TestDdevImportFilesDir
TestDdevRestoreSnapshot TestDdevStartMultipleHostnames TestDdevUploadDirNoPackage
TestDdevXdebugEnabled TestDdevXhprofPrependEnabled TestDdevXhprofXhguiEnabled
TestDebugDeleteVolumeCmd TestDebugRebuildCmd TestEphemeralPortsReusedOnRestart TestGetApps
TestGetAppsEmpty TestHardenedStart TestHttpsRedirection TestMysqlCommand TestPHPConfig
TestPHPWebserverType TestProcessHooks TestProjectAutocompletionForExecCmd
TestRouterPortSubstitutionPersistsAcrossProjects TestSnapshotUncompressed
TestWebserverMariaMySQLDBClient TestWriteDrushConfig
```

Some of the 16 tests that never ran in full may fail after being skipped this long; this PR's run is where that should show up.

🤖 Developed with assistance from [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
stasadev added a commit to stasadev/ddev that referenced this pull request Oct 8, 2026
…hand

## Short Summary (TL;DR)

The all-project-types job is the only CI job that runs tests with `GOTEST_SHORT` unset, and it ran a hand-kept list that had fallen behind, so 16 tests that skip or shrink under `GOTEST_SHORT` never ran in full anywhere. The list is now generated from the tests themselves, so it can't fall behind again.

## The Issue

Found while working on ddev#7904, which changes `TestDebugRebuildCmd`: CI logs show `--- SKIP: TestDebugRebuildCmd` in every job, because Buildkite and `test-reusable.yml` set `GOTEST_SHORT=16` and apache-fpm sets `5`.

The list came from ddev#6693 and broke in three ways:

- ddev#7027 renamed `TestComposerCreateCmd` to `TestComposerCreateProjectCmd`, so that entry has matched nothing since.
- ddev#8028 added `GOTEST_SHORT` skips to `TestDebugRebuildCmd`, `TestDdevImportDB`, `TestDdevRestoreSnapshot`, `TestProcessHooks`, and `TestWebserverMariaMySQLDBClient`, and later PRs did the same for `TestEphemeralPortsReusedOnRestart` (ddev#7992), `TestRouterPortSubstitutionPersistsAcrossProjects` (ddev#8653), `TestSnapshotUncompressed` (ddev#8704), `TestDebugDeleteVolumeCmd` (ddev#8756), and `TestDdevExportDB` (ddev#8798), none of them updating the list.
- `TestComposerVersionConfig`, `TestHttpsRedirection`, `TestMysqlCommand`, `TestDdevStartMultipleHostnames`, and `TestProjectAutocompletionForExecCmd` already did less under `GOTEST_SHORT` when ddev#6693 wrote the list, and weren't on it.

## How This PR Solves The Issue

Tests use three `testcommon` helpers instead of reading `GOTEST_SHORT`: `SkipIfGotestShort(t)`, `IsGotestShort(t)`, and `UsesAllTestSites(t)`, a marker for tests that loop over every test site. `.github/workflows/all-project-types-tests.sh` finds the tests that call them and prints the `-run` pattern, and fails if a test other than `TestMain` reads `GOTEST_SHORT` itself.

The pattern is anchored, so prefix matches such as every `TestCmdStart*` test or `TestAutocompleteServiceForServiceFlag` no longer ride along; like `TestAppdirAlreadyInUse` and `TestConfigValidate`, which also leave the list, they don't depend on `GOTEST_SHORT` and run in every job. The `GOTEST_SHORT` branches that ddev#8028 made unreachable in `TestComposerCreateProjectCmd` and `TestDdevAllDatabases` are removed.

## Manual Testing Instructions

```bash
.github/workflows/all-project-types-tests.sh
# Expect ^(TestAutocompletionForDescribeCmd|...|TestWriteDrushConfig)\b with the 42 tests below
```

Adding `if os.Getenv("GOTEST_SHORT") != "" { t.Skip() }` to any test makes the script print that file and line and exit non-zero.

## Automated Testing Overview

In the all-project-types job, the "Compute TESTARGS" step of `prepare-testargs` should print a `-run '^(...)\b'` pattern with exactly these 42 tests, and the test log should show each of them running, none skipped because of `GOTEST_SHORT`:

```text
TestAutocompletionForDescribeCmd TestAutocompletionForStartCmd TestAutocompletionForStopCmd
TestAvailableUpdates TestCmdDescribe TestCmdDescribeAppFunction TestCmdDescribeAppUsingSitename
TestCmdList TestCmdStart TestCmdStop TestComposerCreateProjectCmd TestComposerVersionConfig
TestConfigDatabaseVersion TestDdevAllDatabases TestDdevExportDB TestDdevFullSiteSetup
TestDdevImportDB TestDdevImportFiles TestDdevImportFilesCustomUploadDir TestDdevImportFilesDir
TestDdevRestoreSnapshot TestDdevStartMultipleHostnames TestDdevUploadDirNoPackage
TestDdevXdebugEnabled TestDdevXhprofPrependEnabled TestDdevXhprofXhguiEnabled
TestDebugDeleteVolumeCmd TestDebugRebuildCmd TestEphemeralPortsReusedOnRestart TestGetApps
TestGetAppsEmpty TestHardenedStart TestHttpsRedirection TestMysqlCommand TestPHPConfig
TestPHPWebserverType TestProcessHooks TestProjectAutocompletionForExecCmd
TestRouterPortSubstitutionPersistsAcrossProjects TestSnapshotUncompressed
TestWebserverMariaMySQLDBClient TestWriteDrushConfig
```

Some of the 16 tests that never ran in full may fail after being skipped this long; this PR's run is where that should show up.

🤖 Developed with assistance from [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants