Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

network: fix random missing network when service has more than one #10778

Merged
merged 1 commit into from
Jul 7, 2023

Conversation

milas
Copy link
Contributor

@milas milas commented Jul 6, 2023

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

Related issue

(not mandatory) A picture of a cute animal, if possible in relation to what you did
a baby panda on a tree branch

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 milas requested a review from a team July 6, 2023 20:41
@milas milas self-assigned this Jul 6, 2023
@milas milas requested review from nicksieger, ndeloof, StefanScherer, ulyssessouza, glours and laurazard and removed request for a team July 6, 2023 20:41
const projectName = "network-e2e"
c := NewCLI(t, WithEnv(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

@codecov
Copy link

codecov bot commented Jul 6, 2023

Codecov Report

Patch coverage: 75.00% and project coverage change: +0.12 🎉

Comparison is base (c496c23) 59.03% compared to head (a1a559c) 59.16%.

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     
Impacted Files Coverage Δ
pkg/compose/convergence.go 68.89% <75.00%> (+0.11%) ⬆️

... and 11 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@ndeloof ndeloof merged commit be22bc7 into docker:v2 Jul 7, 2023
@bf
Copy link

bf commented Jul 11, 2023

This issue cost me a lot of time. Thanks for fixing.

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.

4 participants