[PR #5592] fix(dns): kill DnsCache svchost to flush stale NRPT policy on Windows #28196

Open
opened 2026-08-05 08:05:57 -04:00 by saavagebueno · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/5592
Author: @sbeaudry-qms
Created: 3/12/2026
Status: 🔄 Open

Base: mainHead: fix/windows-dns-cache-nrpt-flush


📝 Commits (2)

  • b978949 fix(dns): kill DnsCache svchost to flush stale NRPT policy on Windows
  • 1ee3f1b fix(dns): address CodeRabbit review feedback

📊 Changes

1 file changed (+80 additions, -1 deletions)

View changed files

📝 client/internal/dns/host_windows.go (+80 -1)

📄 Description

After removing NRPT registry keys on disconnect, DnsCache retains stale rules in memory on Windows builds where the service is NOT_PAUSABLE and ignores PARAMCHANGE signals. This causes DNS queries for NetBird domains to continue resolving to the dead forwarder IP until reboot.

Fix by terminating the svchost process hosting DnsCache after registry cleanup, forcing a cold reload of NRPT policy from the now-clean registry. Windows Service Host respawns DnsCache immediately.

Fixes #5579

Describe your changes

After removeDNSMatchPolicies() deletes NRPT registry keys on disconnect, the DnsCache service on many Windows 10/11 builds retains the stale rules in memory. The service reports NOT_PAUSABLE and silently ignores SERVICE_CONTROL_PARAMCHANGE, so the existing DnsFlushResolverCache call has no effect on loaded policy. This can be confirmed with Get-DnsClientNrptPolicy -Effective — stale rules pointing at the dead NetBird forwarder IP remain visible after disconnect despite the registry being clean.

This fix adds killDNSCacheProcess() which terminates the svchost process hosting DnsCache after registry cleanup. Windows Service Host respawns DnsCache immediately, and the fresh instance reads from the now-clean registry. Network connectivity is not interrupted.

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (internal Windows service lifecycle fix with no user-facing behaviour change)

Docs PR URL (required if "docs added" is checked)

N/A

Summary by CodeRabbit

  • Bug Fixes
    • Improved DNS cache handling on Windows so DNS configuration and policy changes (NRPT) take effect immediately by forcing a fresh resolver instance.
    • If the forced refresh cannot be completed, the system logs a non-fatal warning instead of failing the operation.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbirdio/netbird/pull/5592 **Author:** [@sbeaudry-qms](https://github.com/sbeaudry-qms) **Created:** 3/12/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/windows-dns-cache-nrpt-flush` --- ### 📝 Commits (2) - [`b978949`](https://github.com/netbirdio/netbird/commit/b978949d487def1044d7b00056888afffd65334e) fix(dns): kill DnsCache svchost to flush stale NRPT policy on Windows - [`1ee3f1b`](https://github.com/netbirdio/netbird/commit/1ee3f1be739c1ebf23d7526d45cc903d4bfe14c0) fix(dns): address CodeRabbit review feedback ### 📊 Changes **1 file changed** (+80 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `client/internal/dns/host_windows.go` (+80 -1) </details> ### 📄 Description After removing NRPT registry keys on disconnect, DnsCache retains stale rules in memory on Windows builds where the service is NOT_PAUSABLE and ignores PARAMCHANGE signals. This causes DNS queries for NetBird domains to continue resolving to the dead forwarder IP until reboot. Fix by terminating the svchost process hosting DnsCache after registry cleanup, forcing a cold reload of NRPT policy from the now-clean registry. Windows Service Host respawns DnsCache immediately. Fixes #5579 ## Describe your changes After `removeDNSMatchPolicies()` deletes NRPT registry keys on disconnect, the `DnsCache` service on many Windows 10/11 builds retains the stale rules in memory. The service reports `NOT_PAUSABLE` and silently ignores `SERVICE_CONTROL_PARAMCHANGE`, so the existing `DnsFlushResolverCache` call has no effect on loaded policy. This can be confirmed with `Get-DnsClientNrptPolicy -Effective` — stale rules pointing at the dead NetBird forwarder IP remain visible after disconnect despite the registry being clean. This fix adds `killDNSCacheProcess()` which terminates the svchost process hosting DnsCache after registry cleanup. Windows Service Host respawns DnsCache immediately, and the fresh instance reads from the now-clean registry. Network connectivity is not interrupted. ## Issue ticket number and link - #5579 https://github.com/netbirdio/netbird/issues/5579 ## Stack <!-- branch-stack --> ### Checklist - [x] Is it a bug fix - [ ] Is a typo/documentation fix - [ ] Is a feature enhancement - [ ] It is a refactor - [ ] Created tests that fail without the change (if possible) > By submitting this pull request, you confirm that you have read and agree to the terms of the [Contributor License Agreement](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT.md). ## Documentation Select exactly one: - [ ] I added/updated documentation for this change - [x] Documentation is **not needed** for this change (internal Windows service lifecycle fix with no user-facing behaviour change) ### Docs PR URL (required if "docs added" is checked) N/A <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved DNS cache handling on Windows so DNS configuration and policy changes (NRPT) take effect immediately by forcing a fresh resolver instance. * If the forced refresh cannot be completed, the system logs a non-fatal warning instead of failing the operation. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
saavagebueno added the pull-request label 2026-08-05 08:05:57 -04:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DYNR/netbird#28196