fix(localdns): wait for resolv.conf update after networkctl reload to prevent race condition#7749
Merged
cameronmeissner merged 14 commits intomainfrom Feb 3, 2026
Merged
Conversation
… prevent race condition
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a race condition that occurs after calling networkctl reload to update DNS configuration. Previously, the code would proceed immediately after the reload command without waiting for systemd-resolved to actually update the /run/systemd/resolve/resolv.conf file, potentially causing subsequent operations to work with stale DNS information.
Changes:
- Added
wait_for_dns_config_applied()function that polls resolv.conf to verify DNS configuration changes have been applied - Integrated the wait function after both networkctl reload calls to ensure DNS changes are complete before proceeding
- Added comprehensive test coverage for the new function
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| parts/linux/cloud-init/artifacts/localdns.sh | Implements the new wait_for_dns_config_applied() function and integrates it after networkctl reload calls in disable_dhcp_use_clusterlistener and cleanup_iptables_and_dns |
| spec/parts/linux/cloud-init/artifacts/localdns_spec.sh | Adds comprehensive test coverage for wait_for_dns_config_applied with tests for success cases, timeout cases, edge cases, and partial IP matching |
Update log messages to use Error: prefix when wait_for_dns_config_applied fails, since these are failure conditions (return 1), not warnings. Updated corresponding test assertion.
…ad of being interpreted as regex wildcards
yewmsft
reviewed
Jan 30, 2026
yewmsft
reviewed
Jan 30, 2026
yewmsft
reviewed
Jan 30, 2026
yewmsft
reviewed
Jan 30, 2026
yewmsft
reviewed
Jan 30, 2026
yewmsft
approved these changes
Jan 30, 2026
…conf after shutdown
yewmsft
approved these changes
Feb 2, 2026
cameronmeissner
approved these changes
Feb 2, 2026
cameronmeissner
approved these changes
Feb 3, 2026
Devinwong
pushed a commit
that referenced
this pull request
Feb 3, 2026
… prevent race condition (#7749) Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Devin Wong <wongsiosun@outlook.com>
mxj220
pushed a commit
that referenced
this pull request
Feb 5, 2026
… prevent race condition (#7749) Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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 this PR does / why we need it:
Immediately after networkctl reload, DNS settings may not have propagated from systemd-networkd (via DHCP) to systemd-resolved yet. As a result, /run/systemd/resolve/resolv.conf can still reflect the previous upstream DNS servers when replace_azurednsip_in_corefile runs.
This happens because networkctl reload only triggers a reload request over D-Bus; it does not wait for systemd-networkd to finish reprocessing configuration, re-acquire DHCP leases, or update systemd-resolved.
Which issue(s) this PR fixes:
Fixes #
to test: shellspec --shell bash --format d spec/parts/linux/cloud-init/artifacts/localdns_spec.sh
copied the script to the localdns-enabled node with replacing systemd-notify WATCHDOG=1 with echo systemd-notify WATCHDOG=1 to have the watchdog restart localdns (simulating what cx had before their race condition problem). I have 2 custom vnet dns servers

updated.localdns.corefile has the correct custom vnet dns servers.