[PR #6388] [client] Flush macOS DNS cache when nameserver group recovers #29474

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

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/6388
Author: @DeviaVir
Created: 6/10/2026
Status: 🔄 Open

Base: mainHead: darwin-flush-dns-cache-on-recovery


📝 Commits (2)

  • 50bf7a8 [client] Flush macOS DNS cache when nameserver group recovers
  • 3c604bf [client] Address review: hostManager race, flush coalescing

📊 Changes

1 file changed (+53 additions, -0 deletions)

View changed files

📝 client/internal/dns/server.go (+53 -0)

📄 Description

Describe your changes

Fixes #6387.

On macOS, queries for match domains issued while their overlay upstream is briefly unreachable (typically right after wake from sleep, before tunnels re-establish) get answered by the public resolvers, and mDNSResponder caches the public answer for its full TTL. flushDNSCache currently only runs when the host DNS config is (re)applied, which doesn't happen on a wake without a network change — so clients keep serving the stale public answer for minutes.

This change flushes the OS-level DNS cache when the health projection records an unhealthy → healthy transition for a nameserver group (projectHealthy). The flush is invoked through a type assertion on the host manager, so it's a no-op on every platform except darwin (the only one implementing flushDNSCache), and runs in a goroutine to keep the projection loop non-blocking.

#6387

Stack

  • OS: macOS (code change is platform-neutral, effective only on darwin)
  • NetBird version: main
  • NetBird flags: match-domain nameserver groups with overlay-routed upstreams

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) — covered by existing health-projection tests still passing; the flush itself shells out to dscacheutil/mDNSResponder and isn't unit-testable without a darwin host

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

No user-facing behavior, flags, or APIs change: this is a darwin-only internal bug fix (flush the OS DNS cache on nameserver-group recovery, which macOS users previously worked around manually). Nothing to document beyond the fix itself.

Summary by CodeRabbit

  • Bug Fixes
    • DNS cache is now automatically flushed when a target transitions from unhealthy to healthy, improving DNS resolution immediately after recovery.
    • Cache flushes are coalesced to prevent redundant flush work during rapid or repeated recoveries.
    • Cache flush runs asynchronously; any flush errors are captured as warnings and do not block recovery event emission.

🔄 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/6388 **Author:** [@DeviaVir](https://github.com/DeviaVir) **Created:** 6/10/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `darwin-flush-dns-cache-on-recovery` --- ### 📝 Commits (2) - [`50bf7a8`](https://github.com/netbirdio/netbird/commit/50bf7a81cab5077e28e098a558c1ff768c31d9d4) [client] Flush macOS DNS cache when nameserver group recovers - [`3c604bf`](https://github.com/netbirdio/netbird/commit/3c604bf64bc5d0fb69112550a185ff47063c6e3b) [client] Address review: hostManager race, flush coalescing ### 📊 Changes **1 file changed** (+53 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `client/internal/dns/server.go` (+53 -0) </details> ### 📄 Description ## Describe your changes Fixes #6387. On macOS, queries for match domains issued while their overlay upstream is briefly unreachable (typically right after wake from sleep, before tunnels re-establish) get answered by the public resolvers, and mDNSResponder caches the public answer for its full TTL. `flushDNSCache` currently only runs when the host DNS config is (re)applied, which doesn't happen on a wake without a network change — so clients keep serving the stale public answer for minutes. This change flushes the OS-level DNS cache when the health projection records an unhealthy → healthy transition for a nameserver group (`projectHealthy`). The flush is invoked through a type assertion on the host manager, so it's a no-op on every platform except darwin (the only one implementing `flushDNSCache`), and runs in a goroutine to keep the projection loop non-blocking. ## Issue ticket number and link #6387 ## Stack - OS: macOS (code change is platform-neutral, effective only on darwin) - NetBird version: main - NetBird flags: match-domain nameserver groups with overlay-routed upstreams ## Checklist - [x] Is it a bug fix - [ ] Is a typo/documentation fix - [ ] Is a feature enhancement - [ ] It is a refactor - [x] Created tests that fail without the change (if possible) — covered by existing health-projection tests still passing; the flush itself shells out to `dscacheutil`/`mDNSResponder` and isn't unit-testable without a darwin host ## Documentation Select exactly one: - [ ] I added/updated documentation for this change - [x] Documentation is **not needed** for this change (explain why) No user-facing behavior, flags, or APIs change: this is a darwin-only internal bug fix (flush the OS DNS cache on nameserver-group recovery, which macOS users previously worked around manually). Nothing to document beyond the fix itself. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * DNS cache is now automatically flushed when a target transitions from unhealthy to healthy, improving DNS resolution immediately after recovery. * Cache flushes are coalesced to prevent redundant flush work during rapid or repeated recoveries. * Cache flush runs asynchronously; any flush errors are captured as warnings and do not block recovery event emission. <!-- 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:08:08 -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#29474