Repository navigation
fix(router): recreate router when network aliases change, fixes #8110 - #8132
Merged
Merged
Conversation
|
Download the artifacts for this pull request:
See Testing a PR. |
rfay
added a commit
to rfay/ddev
that referenced
this pull request
Feb 12, 2026
Enhance TestNetworkAliases to properly test issue ddev#8110 by configuring both test projects with identical port configurations (80/443). Previously, app1 used custom ports (8080/8443) while app2 used default ports (80/443), which meant the router would be recreated due to port differences alone. Changes: - Both projects now use the same ports (80/443) to test the scenario where ports match but hostnames differ - Updated test cases to use GetHTTPURL()/GetHTTPSURL() methods for project name tests instead of manually constructing URLs - Added new subtest "router_recreated_for_new_hostname" that specifically validates the issue ddev#8110 fix by verifying both projects can communicate via HTTPS through the router and both hostnames exist as network aliases This ensures the test validates that the router is recreated when hostnames change even if ports remain the same, which is the core fix from PR ddev#8132. Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
rfay
added a commit
to rfay/ddev
that referenced
this pull request
Feb 12, 2026
Enhance TestNetworkAliases to properly test issue ddev#8110 by configuring both test projects with identical port configurations (80/443). Previously, app1 used custom ports (8080/8443) while app2 used default ports (80/443), which meant the router would be recreated due to port differences alone. Changes: - Both projects now use the same ports (80/443) to test the scenario where ports match but hostnames differ - Updated test cases to use GetHTTPURL()/GetHTTPSURL() methods for project name tests instead of manually constructing URLs - Added new subtest "router_recreated_for_new_hostname" that specifically validates the issue ddev#8110 fix by verifying both projects can communicate via HTTPS through the router and both hostnames exist as network aliases This ensures the test validates that the router is recreated when hostnames change even if ports remain the same, which is the core fix from PR ddev#8132. Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
rfay
force-pushed
the
20260211_rfay_network_aliases
branch
from
February 12, 2026 19:17
d713407 to
ca0ae4f
Compare
rfay
marked this pull request as ready for review
February 13, 2026 18:05
rfay
added a commit
to rfay/ddev
that referenced
this pull request
Feb 17, 2026
Enhance TestNetworkAliases to properly test issue ddev#8110 by configuring both test projects with identical port configurations (80/443). Previously, app1 used custom ports (8080/8443) while app2 used default ports (80/443), which meant the router would be recreated due to port differences alone. Changes: - Both projects now use the same ports (80/443) to test the scenario where ports match but hostnames differ - Updated test cases to use GetHTTPURL()/GetHTTPSURL() methods for project name tests instead of manually constructing URLs - Added new subtest "router_recreated_for_new_hostname" that specifically validates the issue ddev#8110 fix by verifying both projects can communicate via HTTPS through the router and both hostnames exist as network aliases This ensures the test validates that the router is recreated when hostnames change even if ports remain the same, which is the core fix from PR ddev#8132. Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
rfay
force-pushed
the
20260211_rfay_network_aliases
branch
from
February 17, 2026 03:17
ca0ae4f to
c84106f
Compare
stasadev
requested changes
Feb 18, 2026
stasadev
left a comment
Member
There was a problem hiding this comment.
Looks good to me and works fine.
We still need to test TestNetworkAliases with different ports, as we did before. I remember this test failed for me when I added aliases at the project level instead of in ddev-router. It is still important to make sure communication on different ports works as expected.
Maybe we should just duplicate the test as TestNetworkAliasesDifferentPorts?
…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]>
Enhance TestNetworkAliases to properly test issue ddev#8110 by configuring both test projects with identical port configurations (80/443). Previously, app1 used custom ports (8080/8443) while app2 used default ports (80/443), which meant the router would be recreated due to port differences alone. Changes: - Both projects now use the same ports (80/443) to test the scenario where ports match but hostnames differ - Updated test cases to use GetHTTPURL()/GetHTTPSURL() methods for project name tests instead of manually constructing URLs - Added new subtest "router_recreated_for_new_hostname" that specifically validates the issue ddev#8110 fix by verifying both projects can communicate via HTTPS through the router and both hostnames exist as network aliases This ensures the test validates that the router is recreated when hostnames change even if ports remain the same, which is the core fix from PR ddev#8132. Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
…elper - Extract runNetworkAliasesTest helper shared by both test functions - TestNetworkAliases keeps same-port scenario (80/443) for ddev#8110 fix coverage - Add TestNetworkAliasesDifferentPorts with app1 on 8080/8443, app2 on 80/443 - Skip entire test early via app.CanUseHTTPOnly() instead of conditionally excluding HTTPS URLs; always test both HTTP and HTTPS - Use strings.Replace(app.GetHTTPURL(), ...) for additional hostname/FQDN URLs so port handling comes from the existing app methods Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
rfay
force-pushed
the
20260211_rfay_network_aliases
branch
from
February 18, 2026 18:44
c84106f to
66faa14
Compare
Member
Author
|
Rebased and added TestNetworkAliasesDifferentPorts |
stasadev
approved these changes
Feb 18, 2026
stasadev
left a comment
Member
There was a problem hiding this comment.
Test refactoring looks great, thank you!
stasadev
added a commit
to stasadev/ddev
that referenced
this pull request
Jul 14, 2026
…n start ## The Issue - Follow-up to ddev#8132, which fixed ddev#8110 PR ddev#8132 made the router recreate itself whenever project hostnames (network aliases) changed, so inter-project HTTP/S communication kept working. That fixed correctness, but it also meant that starting an additional project (`ddev start`) recreated the whole router even though its published ports were unchanged. Router recreation is disruptive and slower than necessary for the common "start another project" case. ## How This PR Solves The Issue Recreation is now reserved for the cases that actually require it, and hostname-only changes are handled without recreating the container: 1. **Added `UpdateContainerNetworkAliases()`** in `pkg/dockerutil/containers.go` - Docker only lets network aliases be set at connect time, so this disconnects and reconnects the router on the `ddev_default` network with the new alias set. No container recreation. 2. **Reworked the recreation decision** in `StartDdevRouter()` (`pkg/ddevapp/router.go`) - The router is recreated only when it is not running, its state can't be read, or its published ports changed (published ports can't be changed on a live container). A hostname-only change no longer triggers recreation. 3. **Update aliases in place when already running** - When the router is already running and only hostnames changed, the network aliases are refreshed in place via `UpdateContainerNetworkAliases()` before the Traefik config is pushed. The correctness guarantee from ddev#8132 is preserved (aliases are always current), while the common case of starting an extra project no longer pays for a full router recreation. ## Manual Testing Instructions ```bash # Clean slate ddev poweroff mkdir -p ~/tmp/t1 ~/tmp/t2 # First project starts (router is created) cd ~/tmp/t1 && ddev config --auto && ddev start printf '<?php\nprint "this is t1\n";' >index.php # Second project starts: router is NOT recreated, aliases updated in place cd ~/tmp/t2 && ddev config --auto && ddev start printf '<?php\nprint "BUT this is t2\n";' >index.php # Aliases include both projects docker inspect ddev-router --format '{{json .NetworkSettings.Networks.ddev_default.Aliases}}' | jq # Should show both t1.ddev.site and t2.ddev.site # Inter-project communication still works cd ~/tmp/t1 ddev exec curl -I https://t2.ddev.site # Router container id stays the same across the second start # (compare `docker inspect ddev-router --format '{{.Id}}'` before/after) ``` ## Automated Testing Overview Existing `TestGetRouterNetworkAliases()` (`pkg/dockerutil`) and `TestHostnamesMatch()` (`pkg/ddevapp`) continue to cover alias extraction and comparison. `TestNetworkAliases()` in `pkg/dockerutil/networks_test.go` exercises the disconnect/reconnect alias update path end-to-end. ## Release/Deployment Notes No user-facing configuration changes. Starting additional projects is faster because the router is no longer recreated for hostname-only changes; recreation still happens when published ports change or the router is not running. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
rfay
pushed a commit
to stasadev/ddev
that referenced
this pull request
Jul 17, 2026
…n start ## The Issue - Follow-up to ddev#8132, which fixed ddev#8110 PR ddev#8132 made the router recreate itself whenever project hostnames (network aliases) changed, so inter-project HTTP/S communication kept working. That fixed correctness, but it also meant that starting an additional project (`ddev start`) recreated the whole router even though its published ports were unchanged. Router recreation is disruptive and slower than necessary for the common "start another project" case. ## How This PR Solves The Issue Recreation is now reserved for the cases that actually require it, and hostname-only changes are handled without recreating the container: 1. **Added `UpdateContainerNetworkAliases()`** in `pkg/dockerutil/containers.go` - Docker only lets network aliases be set at connect time, so this disconnects and reconnects the router on the `ddev_default` network with the new alias set. No container recreation. 2. **Reworked the recreation decision** in `StartDdevRouter()` (`pkg/ddevapp/router.go`) - The router is recreated only when it is not running, its state can't be read, or its published ports changed (published ports can't be changed on a live container). A hostname-only change no longer triggers recreation. 3. **Update aliases in place when already running** - When the router is already running and only hostnames changed, the network aliases are refreshed in place via `UpdateContainerNetworkAliases()` before the Traefik config is pushed. The correctness guarantee from ddev#8132 is preserved (aliases are always current), while the common case of starting an extra project no longer pays for a full router recreation. ## Manual Testing Instructions ```bash # Clean slate ddev poweroff mkdir -p ~/tmp/t1 ~/tmp/t2 # First project starts (router is created) cd ~/tmp/t1 && ddev config --auto && ddev start printf '<?php\nprint "this is t1\n";' >index.php # Second project starts: router is NOT recreated, aliases updated in place cd ~/tmp/t2 && ddev config --auto && ddev start printf '<?php\nprint "BUT this is t2\n";' >index.php # Aliases include both projects docker inspect ddev-router --format '{{json .NetworkSettings.Networks.ddev_default.Aliases}}' | jq # Should show both t1.ddev.site and t2.ddev.site # Inter-project communication still works cd ~/tmp/t1 ddev exec curl -I https://t2.ddev.site # Router container id stays the same across the second start # (compare `docker inspect ddev-router --format '{{.Id}}'` before/after) ``` ## Automated Testing Overview Existing `TestGetRouterNetworkAliases()` (`pkg/dockerutil`) and `TestHostnamesMatch()` (`pkg/ddevapp`) continue to cover alias extraction and comparison. `TestNetworkAliases()` in `pkg/dockerutil/networks_test.go` exercises the disconnect/reconnect alias update path end-to-end. ## Release/Deployment Notes No user-facing configuration changes. Starting additional projects is faster because the router is no longer recreated for hostname-only changes; recreation still happens when published ports change or the router is not running. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
stasadev
added a commit
to stasadev/ddev
that referenced
this pull request
Jul 17, 2026
…n start ## The Issue - Follow-up to ddev#8132, which fixed ddev#8110 PR ddev#8132 made the router recreate itself whenever project hostnames (network aliases) changed, so inter-project HTTP/S communication kept working. That fixed correctness, but it also meant that starting an additional project (`ddev start`) recreated the whole router even though its published ports were unchanged. Router recreation is disruptive and slower than necessary for the common "start another project" case. ## How This PR Solves The Issue Recreation is now reserved for the cases that actually require it, and hostname-only changes are handled without recreating the container: 1. **Added `UpdateContainerNetworkAliases()`** in `pkg/dockerutil/containers.go` - Docker only lets network aliases be set at connect time, so this disconnects and reconnects the router on the `ddev_default` network with the new alias set. No container recreation. 2. **Reworked the recreation decision** in `StartDdevRouter()` (`pkg/ddevapp/router.go`) - The router is recreated only when it is not running, its state can't be read, or its published ports changed (published ports can't be changed on a live container). A hostname-only change no longer triggers recreation. 3. **Update aliases in place when already running** - When the router is already running and only hostnames changed, the network aliases are refreshed in place via `UpdateContainerNetworkAliases()` before the Traefik config is pushed. The correctness guarantee from ddev#8132 is preserved (aliases are always current), while the common case of starting an extra project no longer pays for a full router recreation. ## Manual Testing Instructions ```bash # Clean slate ddev poweroff mkdir -p ~/tmp/t1 ~/tmp/t2 # First project starts (router is created) cd ~/tmp/t1 && ddev config --auto && ddev start printf '<?php\nprint "this is t1\n";' >index.php # Second project starts: router is NOT recreated, aliases updated in place cd ~/tmp/t2 && ddev config --auto && ddev start printf '<?php\nprint "BUT this is t2\n";' >index.php # Aliases include both projects docker inspect ddev-router --format '{{json .NetworkSettings.Networks.ddev_default.Aliases}}' | jq # Should show both t1.ddev.site and t2.ddev.site # Inter-project communication still works cd ~/tmp/t1 ddev exec curl -I https://t2.ddev.site # Router container id stays the same across the second start # (compare `docker inspect ddev-router --format '{{.Id}}'` before/after) ``` ## Automated Testing Overview Existing `TestGetRouterNetworkAliases()` (`pkg/dockerutil`) and `TestHostnamesMatch()` (`pkg/ddevapp`) continue to cover alias extraction and comparison. `TestNetworkAliases()` in `pkg/dockerutil/networks_test.go` exercises the disconnect/reconnect alias update path end-to-end. ## Release/Deployment Notes No user-facing configuration changes. Starting additional projects is faster because the router is no longer recreated for hostname-only changes; recreation still happens when published ports change or the router is not running. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
stasadev
added a commit
to stasadev/ddev
that referenced
this pull request
Jul 17, 2026
…n start ## The Issue - Follow-up to ddev#8132, which fixed ddev#8110 PR ddev#8132 made the router recreate itself whenever project hostnames (network aliases) changed, so inter-project HTTP/S communication kept working. That fixed correctness, but it also meant that starting an additional project (`ddev start`) recreated the whole router even though its published ports were unchanged. Router recreation is disruptive and slower than necessary for the common "start another project" case. ## How This PR Solves The Issue Recreation is now reserved for the cases that actually require it, and hostname-only changes are handled without recreating the container: 1. **Added `UpdateContainerNetworkAliases()`** in `pkg/dockerutil/containers.go` - Docker only lets network aliases be set at connect time, so this disconnects and reconnects the router on the `ddev_default` network with the new alias set. No container recreation. 2. **Reworked the recreation decision** in `StartDdevRouter()` (`pkg/ddevapp/router.go`) - The router is recreated only when it is not running, its state can't be read, or its published ports changed (published ports can't be changed on a live container). A hostname-only change no longer triggers recreation. 3. **Update aliases in place when already running** - When the router is already running and only hostnames changed, the network aliases are refreshed in place via `UpdateContainerNetworkAliases()` before the Traefik config is pushed. The correctness guarantee from ddev#8132 is preserved (aliases are always current), while the common case of starting an extra project no longer pays for a full router recreation. ## Manual Testing Instructions ```bash # Clean slate ddev poweroff mkdir -p ~/tmp/t1 ~/tmp/t2 # First project starts (router is created) cd ~/tmp/t1 && ddev config --auto && ddev start printf '<?php\nprint "this is t1\n";' >index.php # Second project starts: router is NOT recreated, aliases updated in place cd ~/tmp/t2 && ddev config --auto && ddev start printf '<?php\nprint "BUT this is t2\n";' >index.php # Aliases include both projects docker inspect ddev-router --format '{{json .NetworkSettings.Networks.ddev_default.Aliases}}' | jq # Should show both t1.ddev.site and t2.ddev.site # Inter-project communication still works cd ~/tmp/t1 ddev exec curl -I https://t2.ddev.site # Router container id stays the same across the second start # (compare `docker inspect ddev-router --format '{{.Id}}'` before/after) ``` ## Automated Testing Overview Existing `TestGetRouterNetworkAliases()` (`pkg/dockerutil`) and `TestHostnamesMatch()` (`pkg/ddevapp`) continue to cover alias extraction and comparison. `TestNetworkAliases()` in `pkg/dockerutil/networks_test.go` exercises the disconnect/reconnect alias update path end-to-end. ## Release/Deployment Notes No user-facing configuration changes. Starting additional projects is faster because the router is no longer recreated for hostname-only changes; recreation still happens when published ports change or the router is not running. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
stasadev
added a commit
to stasadev/ddev
that referenced
this pull request
Jul 18, 2026
…n start ## The Issue - Follow-up to ddev#8132, which fixed ddev#8110 PR ddev#8132 made the router recreate itself whenever project hostnames (network aliases) changed, so inter-project HTTP/S communication kept working. That fixed correctness, but it also meant that starting an additional project (`ddev start`) recreated the whole router even though its published ports were unchanged. Router recreation is disruptive and slower than necessary for the common "start another project" case. ## How This PR Solves The Issue Recreation is now reserved for the cases that actually require it, and hostname-only changes are handled without recreating the container: 1. **Added `UpdateContainerNetworkAliases()`** in `pkg/dockerutil/containers.go` - Docker only lets network aliases be set at connect time, so this disconnects and reconnects the router on the `ddev_default` network with the new alias set. No container recreation. 2. **Reworked the recreation decision** in `StartDdevRouter()` (`pkg/ddevapp/router.go`) - The router is recreated only when it is not running, its state can't be read, or its published ports changed (published ports can't be changed on a live container). A hostname-only change no longer triggers recreation. 3. **Update aliases in place when already running** - When the router is already running and only hostnames changed, the network aliases are refreshed in place via `UpdateContainerNetworkAliases()` before the Traefik config is pushed. The correctness guarantee from ddev#8132 is preserved (aliases are always current), while the common case of starting an extra project no longer pays for a full router recreation. ## Manual Testing Instructions ```bash # Clean slate ddev poweroff mkdir -p ~/tmp/t1 ~/tmp/t2 # First project starts (router is created) cd ~/tmp/t1 && ddev config --auto && ddev start printf '<?php\nprint "this is t1\n";' >index.php # Second project starts: router is NOT recreated, aliases updated in place cd ~/tmp/t2 && ddev config --auto && ddev start printf '<?php\nprint "BUT this is t2\n";' >index.php # Aliases include both projects docker inspect ddev-router --format '{{json .NetworkSettings.Networks.ddev_default.Aliases}}' | jq # Should show both t1.ddev.site and t2.ddev.site # Inter-project communication still works cd ~/tmp/t1 ddev exec curl -I https://t2.ddev.site # Router container id stays the same across the second start # (compare `docker inspect ddev-router --format '{{.Id}}'` before/after) ``` ## Automated Testing Overview Existing `TestGetRouterNetworkAliases()` (`pkg/dockerutil`) and `TestHostnamesMatch()` (`pkg/ddevapp`) continue to cover alias extraction and comparison. `TestNetworkAliases()` in `pkg/dockerutil/networks_test.go` exercises the disconnect/reconnect alias update path end-to-end. ## Release/Deployment Notes No user-facing configuration changes. Starting additional projects is faster because the router is no longer recreated for hostname-only changes; recreation still happens when published ports change or the router is not running. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
stasadev
added a commit
to stasadev/ddev
that referenced
this pull request
Jul 29, 2026
…n start ## The Issue - Follow-up to ddev#8132, which fixed ddev#8110 PR ddev#8132 made the router recreate itself whenever project hostnames (network aliases) changed, so inter-project HTTP/S communication kept working. That fixed correctness, but it also meant that starting an additional project (`ddev start`) recreated the whole router even though its published ports were unchanged. Router recreation is disruptive and slower than necessary for the common "start another project" case. ## How This PR Solves The Issue Recreation is now reserved for the cases that actually require it, and hostname-only changes are handled without recreating the container: 1. **Added `UpdateContainerNetworkAliases()`** in `pkg/dockerutil/containers.go` - Docker only lets network aliases be set at connect time, so this disconnects and reconnects the router on the `ddev_default` network with the new alias set. No container recreation. 2. **Reworked the recreation decision** in `StartDdevRouter()` (`pkg/ddevapp/router.go`) - The router is recreated only when it is not running, its state can't be read, or its published ports changed (published ports can't be changed on a live container). A hostname-only change no longer triggers recreation. 3. **Update aliases in place when already running** - When the router is already running and only hostnames changed, the network aliases are refreshed in place via `UpdateContainerNetworkAliases()` before the Traefik config is pushed. The correctness guarantee from ddev#8132 is preserved (aliases are always current), while the common case of starting an extra project no longer pays for a full router recreation. ## Manual Testing Instructions ```bash # Clean slate ddev poweroff mkdir -p ~/tmp/t1 ~/tmp/t2 # First project starts (router is created) cd ~/tmp/t1 && ddev config --auto && ddev start printf '<?php\nprint "this is t1\n";' >index.php # Second project starts: router is NOT recreated, aliases updated in place cd ~/tmp/t2 && ddev config --auto && ddev start printf '<?php\nprint "BUT this is t2\n";' >index.php # Aliases include both projects docker inspect ddev-router --format '{{json .NetworkSettings.Networks.ddev_default.Aliases}}' | jq # Should show both t1.ddev.site and t2.ddev.site # Inter-project communication still works cd ~/tmp/t1 ddev exec curl -I https://t2.ddev.site # Router container id stays the same across the second start # (compare `docker inspect ddev-router --format '{{.Id}}'` before/after) ``` ## Automated Testing Overview Existing `TestGetRouterNetworkAliases()` (`pkg/dockerutil`) and `TestHostnamesMatch()` (`pkg/ddevapp`) continue to cover alias extraction and comparison. `TestNetworkAliases()` in `pkg/dockerutil/networks_test.go` exercises the disconnect/reconnect alias update path end-to-end. ## Release/Deployment Notes No user-facing configuration changes. Starting additional projects is faster because the router is no longer recreated for hostname-only changes; recreation still happens when published ports change or the router is not running. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
rfay
added a commit
that referenced
this pull request
Jul 29, 2026
…n start, for #8132 (#8561) [skip ci] Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> Co-authored-by: Randy Fay <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Issue
When starting a second DDEV project with identical port configuration (even just generic projects show it), the router optimization from PR #7992 prevented recreation because ports matched. However, network aliases in
.router-compose-full.yaml(required by PR #7642 for inter-project 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:
Added
GetRouterNetworkAliases()inpkg/dockerutil/containers.go- Extracts network aliases from the running router container'sddev_defaultnetwork configuration, mirroring the pattern ofGetBoundHostPorts()Added
HostnamesMatch()inpkg/ddevapp/router.go- Compares existing vs needed hostnames using subset matching (allows extra hostnames from stopped projects), exactly mirroringPortsMatch()logicModified
StartDdevRouter()inpkg/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 changedThe fix maintains the performance optimization from PR #7992 (router isn't recreated unnecessarily) while ensuring network aliases are always updated when new projects start.
Manual Testing Instructions
Test a variant of the excellent reproduction scenario from issue #8110:
Automated Testing Overview
New Unit Tests:
TestHostnamesMatch()inpkg/ddevapp/router_test.go- 6 test cases verifying hostname comparison logic mirrorsTestPortsMatch()behavior (empty slices, identical, different order, missing hostname, extra hostnames)TestGetRouterNetworkAliases()inpkg/dockerutil/containers_test.go- Verifies alias extraction from containers, error handlingIntegration Tests:
TestNetworkAliases()inpkg/dockerutil/networks_test.gowill verify the fix works end-to-end (can be enhanced with same-port scenario)All tests pass. golangci-lint passes with 0 issues.