[PR #5794] [CLOSED] [client] Add TTL-based cache refresh for management DNS resolver #23942

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

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/5794
Author: @plusls
Created: 4/3/2026
Status: Closed

Base: mainHead: fix_mgnt_dns_cache


📝 Commits (4)

  • 4edc62d [client] Add TTL-based cache refresh for management DNS resolver
  • a7b3f19 [client] Add backoff after failed DNS cache refresh
  • 6a59a2f [client] Add backoff when DNS returns empty records for cached type
  • da96f92 [client] Re-read cache entry after acquiring refresh lock

📊 Changes

1 file changed (+85 additions, -8 deletions)

View changed files

📝 client/internal/dns/mgmt/mgmt.go (+85 -8)

📄 Description

Describe your changes

Add TTL expiration mechanism to MgmtCacheResolver to handle DDNS IP changes. When cache entries expire (300s TTL), refresh synchronously using net.DefaultResolver. On refresh failure, serve stale cache to maintain connectivity.

Fixes #5113

https://github.com/netbirdio/netbird/issues/5113

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 (explain why)

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

Paste the PR link from https://github.com/netbirdio/docs here:

https://github.com/netbirdio/docs/pull/__

Summary by CodeRabbit

  • Bug Fixes
    • Improved DNS resolver caching with per-entry timestamps, TTL-based expiration, and automatic refresh of stale records. Failed refreshes now trigger a backoff while continuing to serve stale records for reliability. New logic also records insertion times and applies consistent TTLs to cached responses.

🔄 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/5794 **Author:** [@plusls](https://github.com/plusls) **Created:** 4/3/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix_mgnt_dns_cache` --- ### 📝 Commits (4) - [`4edc62d`](https://github.com/netbirdio/netbird/commit/4edc62d807262403b1bedc83d3b4ae099501cbb5) [client] Add TTL-based cache refresh for management DNS resolver - [`a7b3f19`](https://github.com/netbirdio/netbird/commit/a7b3f1979987205f6eaaff1c34d3fbc776b732dd) [client] Add backoff after failed DNS cache refresh - [`6a59a2f`](https://github.com/netbirdio/netbird/commit/6a59a2f1439fc6ef9200a4b9b1b9cc10e97edd58) [client] Add backoff when DNS returns empty records for cached type - [`da96f92`](https://github.com/netbirdio/netbird/commit/da96f9225f5a6267387bd59b68188c6b69db8d20) [client] Re-read cache entry after acquiring refresh lock ### 📊 Changes **1 file changed** (+85 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `client/internal/dns/mgmt/mgmt.go` (+85 -8) </details> ### 📄 Description ## Describe your changes Add TTL expiration mechanism to MgmtCacheResolver to handle DDNS IP changes. When cache entries expire (300s TTL), refresh synchronously using net.DefaultResolver. On refresh failure, serve stale cache to maintain connectivity. Fixes #5113 ## Issue ticket number and link https://github.com/netbirdio/netbird/issues/5113 ## 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 (explain why) ### Docs PR URL (required if "docs added" is checked) Paste the PR link from https://github.com/netbirdio/docs here: https://github.com/netbirdio/docs/pull/__ <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved DNS resolver caching with per-entry timestamps, TTL-based expiration, and automatic refresh of stale records. Failed refreshes now trigger a backoff while continuing to serve stale records for reliability. New logic also records insertion times and applies consistent TTLs to cached responses. <!-- 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 06:08:02 -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#23942