fix(network): make address selection deterministic across layers#22043
Merged
fix(network): make address selection deterministic across layers#22043
Conversation
63fe274 to
7af92a9
Compare
manadart
approved these changes
Mar 30, 2026
Member
manadart
left a comment
There was a problem hiding this comment.
Thanks.
Based on how things are going, this logic is probably on borrowed time, but the change is correct for now.
nvinuesa
approved these changes
Mar 31, 2026
Member
nvinuesa
left a comment
There was a problem hiding this comment.
LGTM, good test coverage, thanks.
Comment on lines
+45
to
+47
| // AllMatchingScope already falls back to public addresses if no | ||
| // cloud-local address exists. If we still have no match, only | ||
| // unsuitable addresses (localhost, link-local) remain. |
Member
There was a problem hiding this comment.
As @manadart mentioned, this will probably follow the same kind of implementation as GetUnitPublicAddresses() (i.e. handle the matching/sorting on the state layer with proper SQL).
992532a to
435893b
Compare
Contributor
Author
|
/merge |
jujubot
added a commit
that referenced
this pull request
Apr 2, 2026
#22139 ## Merged PR's - #22122 @SimonRichardson - #22123 @jack-w-shaw - #22124 @SimonRichardson - #22125 @SimonRichardson - #22131 @tonyandrewmeyer - #22117 @gfouillet/v4.0/fix - #22090 @hmlanigan - #22087 @tmihoc - #22116 @jack-w-shaw - #22102 @SimonRichardson - #22043 @iyiguncevik - #22086 @SimonRichardson - #22047 @nvinuesa - #21848 @nvinuesa - #22103 @nvinuesa - #21352 @hpidcock - #22109 @kian99 - #22093 @gfouillet/v4.0/ci - #21834 @manadart - #22036 @nvinuesa - #22079 @manadart - #22046 @SimonRichardson - #22029 @SimonRichardson - #22055 @tmihoc - #22085 @SimonRichardson - #21928 @hpidcock - #22054 @manadart - #22082 @jack-w-shaw - #22068 @jack-w-shaw - #22025 @hmlanigan - #22045 @gfouillet/v4.0/fix - #22049 @wallyworld - #21985 @anvial - #22028 @hmlanigan - #22031 @gfouillet/v4.0/fix - #22022 @gfouillet/v4.0/fix - #22008 @nvinuesa - #22007 @jonathan-conder - #22027 @gfouillet/v4.0/fix - #21725 @hpidcock - #22005 @wallyworld - #21981 @tlm - #21968 @anvial - #21987 @manadart - #22014 @gfouillet/v4.0/fix - #22011 @gfouillet/v4.0/fix - #21960 @tlm - #21918 @manadart - #21925 @hmlanigan - #22009 @manadart - #21880 @manadart - #22010 @jack-w-shaw - #22001 @jack-w-shaw - #21982 @wallyworld ## Conflicts - `apiserver/facades/client/applicationoffers/applicationoffers_test.go` - `core/version/version.go` - `domain/schema/controller.go` - `domain/schema/model.go` - `scripts/win-installer/setup.iss` - `snap/snapcraft.yaml` ## Patches - Controller / `0029-tracing.PATCH.sql` - Model / `0052-resource.PATCH.sql`
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.
This PR fixes non-deterministic address selection by making scope-based
matching deterministic and by clarifying layer responsibilities between network
state and service code.
The issue is that callers often select the first matching address; when
candidate order is unstable, selected addresses can vary across runs.
What changed:
domain/network/state/unitinfo.go+domain/network/service/unitinfo.go—no change. This was fixed in fix: filter virtual ethernet devices for relation networks #22054core/network/address.go: UpdatedSpaceAddresses.AllMatchingScopeto return deterministically sorted matches —this is the most important change.domain/network/service/unitaddress.go: GetUnitPrivateAddress now:domain/status/state/model/modelstate.go—no change. It is intentionally left unchanged in this PR becauseGetMachineFullStatusescurrently has downstream expectations on that shape/contract, so “fixing” it here would break expected behavior.Checklist
Integration tests, with comments saying what you're testingdoc.go added or updated in changed packagesQA steps
Setup network interfaces:
❯ lxc network create lxdbr1 \ ipv4.address=10.155.6.1/24 \ ipv4.nat=true \ ipv6.address=none ❯ lxc network create lxdbr2 \ ipv4.address=10.155.2.1/24 \ ipv4.nat=true \ ipv6.address=none ❯ lxc network create lxdbr3 \ ipv4.address=10.155.3.1/24 \ ipv4.nat=true \ ipv6.address=none ❯ lxc network list ❯ lxc profile device add default eth1 nic \ network=lxdbr1 name=eth1 ❯ lxc profile device add default eth2 nic \ network=lxdbr2 name=eth2 ❯ lxc profile device add default eth3 nic \ network=lxdbr3 name=eth3 ❯ lxc profile show default | yq '.devices' eth0: name: eth0 network: lxdbr0 type: nic eth1: name: eth1 network: lxdbr1 type: nic eth2: name: eth2 network: lxdbr2 type: nic eth3: name: eth3 network: lxdbr3 type: nic root: path: / pool: default type: disk ❯ juju bootstrap lxd srcVerify IP addresses
Documentation changes
Links
Issue: Fixes #21809
Jira card: JUJU-9244