Skip to content

fix: add pre-create NIC readiness gate before New-HNSNetwork to avoid windows race condition#8008

Merged
timmy-wright merged 17 commits intomainfrom
timmy/hns-fix
Mar 5, 2026
Merged

fix: add pre-create NIC readiness gate before New-HNSNetwork to avoid windows race condition#8008
timmy-wright merged 17 commits intomainfrom
timmy/hns-fix

Conversation

@timmy-wright
Copy link
Copy Markdown
Contributor

@timmy-wright timmy-wright commented Mar 4, 2026

Problem

When New-HNSNetwork is called while the primary NIC is still transitioning from its APIPA (169.254/16) address to its DHCP address, HNS latches the APIPA address as ProviderAddress. Since HNS doesn't proactively update ProviderAddress after creation, this persists and causes node provisioning failures.

Fix

Added a pre-create readiness gate in New-ExternalHnsNetwork (azurecnifunc.ps1) that polls the chosen network adapter for a stable, non-APIPA IPv4 address in Preferred state before calling New-HNSNetwork. The gate:

  • Polls Get-NetIPAddress every 500ms, up to 120 seconds
  • Proceeds immediately once a non-169.254.x.x Preferred IP is found
  • If it times out, logs a warning and proceeds (existing post-create checks remain as the safety net)

Tests

Added Describe 'New-ExternalHnsNetwork' Pester tests covering:

  • Stable Preferred IP found immediately → no retries, New-HNSNetwork called once
  • APIPA initially, stable IP appears after retries → gate waits then proceeds
  • Gate timeout (all APIPA) → logs warning but still calls New-HNSNetwork
  • Dual-stack mode → correct dual-stack address prefixes passed

Copilot AI review requested due to automatic review settings March 4, 2026 00:50
@timmy-wright timmy-wright changed the title bug: [Windows] Fix race condition: add pre-create NIC readiness gate before New-HNSNetwork fix: [Windows] Fix race condition: add pre-create NIC readiness gate before New-HNSNetwork Mar 4, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Addresses a Windows node provisioning race where New-HNSNetwork can latch an APIPA address as ProviderAddress if the primary NIC is still transitioning to its DHCP address.

Changes:

  • Add a pre-create readiness gate in New-ExternalHnsNetwork to wait (up to 120s) for a stable, non-APIPA IPv4 in Preferred state before calling New-HNSNetwork.
  • Add Pester tests for the new readiness-gate behaviors and dual-stack invocation shape.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
staging/cse/windows/azurecnifunc.ps1 Adds pre-create polling gate to avoid HNS latching APIPA ProviderAddress during NIC transition.
staging/cse/windows/azurecnifunc.tests.ps1 Adds Pester coverage for the readiness gate and dual-stack New-HNSNetwork call pattern.

Comment thread staging/cse/windows/azurecnifunc.tests.ps1
Comment thread staging/cse/windows/azurecnifunc.tests.ps1
@timmy-wright timmy-wright changed the title fix: [Windows] Fix race condition: add pre-create NIC readiness gate before New-HNSNetwork fix(windows): Fix race condition: add pre-create NIC readiness gate before New-HNSNetwork Mar 4, 2026
@timmy-wright timmy-wright changed the title fix(windows): Fix race condition: add pre-create NIC readiness gate before New-HNSNetwork fix(windows): fix race condition: add pre-create NIC readiness gate before New-HNSNetwork Mar 4, 2026
@timmy-wright timmy-wright changed the title fix(windows): fix race condition: add pre-create NIC readiness gate before New-HNSNetwork fix: windows race condition - add pre-create NIC readiness gate before New-HNSNetwork Mar 4, 2026
@timmy-wright timmy-wright changed the title fix: windows race condition - add pre-create NIC readiness gate before New-HNSNetwork fix: add pre-create NIC readiness gate before New-HNSNetwork to avoid windows race condition Mar 4, 2026
Copilot AI review requested due to automatic review settings March 4, 2026 21:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread staging/cse/windows/azurecnifunc.ps1 Outdated
Comment thread staging/cse/windows/azurecnifunc.tests.ps1
Comment thread staging/cse/windows/azurecnifunc.ps1 Outdated
Comment thread staging/cse/windows/azurecnifunc.ps1 Outdated
Copilot AI review requested due to automatic review settings March 4, 2026 21:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread staging/cse/windows/azurecnifunc.tests.ps1
Copilot AI review requested due to automatic review settings March 4, 2026 22:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread staging/cse/windows/azurecnifunc.tests.ps1
Comment thread staging/cse/windows/azurecnifunc.ps1 Outdated
@timmy-wright timmy-wright merged commit 6e2dbb2 into main Mar 5, 2026
28 of 29 checks passed
@timmy-wright timmy-wright deleted the timmy/hns-fix branch March 5, 2026 01:17
janenotjung-hue pushed a commit that referenced this pull request Mar 11, 2026
saewoni pushed a commit that referenced this pull request Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants