network: fix random missing network when service has more than one#10778
Merged
network: fix random missing network when service has more than one#10778
Conversation
As part of the fix for docker#10668, the logic was adjusted so that the default (highest-priority) network is used in the `ContainerCreate`, and then the remaining networks are connected via calls to `NetworkConnect` before starting the container. Unfortunately, `ServiceConfig::NetworksByPriority` is neither deterministic nor stable when networks have the same priority. It's non-deterministic because the order of networks from parsing YAML is random, since they are loaded into a Go map (which have random iteration order). Additionally, it's not using a `SortStable` in `compose-go`, so even if the load order was predictable, it still might produce different results. While I look at improving `compose-go` here to prevent this from tripping us up in the future, this fix looks at _all_ networks for a service and ignores the "default" one now. Before, it would always skip the first one in the slice since that _should_ have been the "default". Signed-off-by: Milas Bowman <milas.bowman@docker.com>
milas
commented
Jul 6, 2023
| c := NewCLI(t) | ||
|
|
||
| const projectName = "network-e2e" | ||
| c := NewCLI(t, WithEnv( |
Contributor
Author
There was a problem hiding this comment.
fyi this test is functionally the same, I just removed the "subtests" since it's really one test, used WithEnv to shorten the commands, and added a -t0 on the down so that it's faster
glours
approved these changes
Jul 6, 2023
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## v2 #10778 +/- ##
==========================================
+ Coverage 59.03% 59.16% +0.12%
==========================================
Files 113 115 +2
Lines 9774 9854 +80
==========================================
+ Hits 5770 5830 +60
- Misses 3419 3433 +14
- Partials 585 591 +6
☔ View full report in Codecov by Sentry. |
ndeloof
approved these changes
Jul 7, 2023
|
This issue cost me a lot of time. Thanks for fixing. |
This was referenced Jul 21, 2023
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.
What I did
As part of the fix for #10668, the logic was adjusted so that the default (highest-priority) network is used in the
ContainerCreate, and then the remaining networks are connected via calls toNetworkConnectbefore starting the container.Unfortunately,
ServiceConfig::NetworksByPriorityis neither deterministic nor stable when networks have the same priority.It's non-deterministic because the order of networks from parsing YAML is random, since they are loaded into a Go map (which have random iteration order). Additionally, it's not using a
SortStableincompose-go, so even if the load order was predictable, it still might produce different results.While I look at improving
compose-gohere to prevent this from tripping us up in the future, this fix looks at all networks for a service and ignores the "default" one now. Before, it would always skip the first one in the slice since that should have been the "default".Related issue
Host name lookup failureor missing networks when using multiple networks #10777(not mandatory) A picture of a cute animal, if possible in relation to what you did
