Skip to content

[client] lookup for management domains using an additional timeout#4983

Merged
mlsmaycon merged 2 commits intomainfrom
handle-mgmt-dns-cache-timeouts
Dec 22, 2025
Merged

[client] lookup for management domains using an additional timeout#4983
mlsmaycon merged 2 commits intomainfrom
handle-mgmt-dns-cache-timeouts

Conversation

@mlsmaycon
Copy link
Copy Markdown
Collaborator

@mlsmaycon mlsmaycon commented Dec 22, 2025

Describe your changes

in some cases iOS and macOS may be locked when looking for management domains during network changes

This change introduce an additional timeout on top of the context call

Issue ticket number and link

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 IP lookup reliability with extended timeout, better error propagation, and cancellation handling.
  • Improvements

    • Added asynchronous lookup behavior with timeout-aware handling and clearer start/done/warning logs for DNS resolution.

✏️ Tip: You can customize this high-level summary in your review settings.

in some cases iOS and macOS may be locked when looking for management domains during network changes

This change introduce an additional timeout on top of the context call
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Dec 22, 2025

Walkthrough

Adds an async DNS lookup helper with extended timeout and an internal result type; replaces direct resolver calls with the helper in AddDomain, adding logging, timeout warning, context cancellation handling, and error propagation.

Changes

Cohort / File(s) Change Summary
DNS lookup helper & AddDomain replacement
client/internal/dns/mgmt/mgmt.go
Adds internal ipsResponse type and lookupIPWithExtraTimeout(ctx context.Context, d domain.Domain) ([]netip.Addr, error). Implements asynchronous DNS resolution via goroutine + channel, select-based extended timeout handling, context cancellation, and logging. Replaces direct net.DefaultResolver.LookupNetIP usage in AddDomain with the new helper while preserving error surface.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review goroutine and channel lifecycle for potential leaks or races in lookupIPWithExtraTimeout
  • Validate select-based timeout and context cancellation paths for correctness and deterministic behavior
  • Confirm logging and error propagation preserve previous semantics used by AddDomain

Poem

🐇 I hopped through code to chase an IP,
Spawned a goroutine, set a timeout clip.
Context whispers stop, the resolver replies,
Addresses found beneath network skies.
I nibble logs and bounce—another DNS surprise!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding an additional timeout mechanism for management domain lookups in the client DNS module.
Description check ✅ Passed The description follows the template structure with completed sections: change description, bug fix checklist, and documentation justification. All required elements are present though some optional fields are unused.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch handle-mgmt-dns-cache-timeouts

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 04d8f7c and c18b2cd.

📒 Files selected for processing (1)
  • client/internal/dns/mgmt/mgmt.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • client/internal/dns/mgmt/mgmt.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (13)
  • GitHub Check: Linux
  • GitHub Check: Darwin
  • GitHub Check: Windows
  • GitHub Check: iOS / Build
  • GitHub Check: Android / Build
  • GitHub Check: Client / Unit
  • GitHub Check: Build Cache
  • GitHub Check: Client / Unit
  • GitHub Check: release_ui_darwin
  • GitHub Check: release_ui
  • GitHub Check: release
  • GitHub Check: Client / Unit
  • GitHub Check: JS / Lint

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment thread client/internal/dns/mgmt/mgmt.go Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
client/internal/dns/mgmt/mgmt.go (1)

168-196: Consider minor naming and logging refinements.

The async lookup implementation is correct and the buffered channel ensures no goroutine leaks. A few optional suggestions:

  1. Channel naming: errChan carries both IPs and error; respChan would be more accurate.

  2. Logging level: Info level for every lookup start/done may be verbose in production. Consider Debug for the routine messages, keeping Warn for the timeout case.

🔎 Proposed refinements
 func lookupIPWithExtraTimeout(ctx context.Context, d domain.Domain) ([]netip.Addr, error) {
-	log.Infof("looking up IP for mgmt domain=%s", d.SafeString())
-	defer log.Infof("done looking up IP for mgmt domain=%s", d.SafeString())
-	errChan := make(chan *ipsResponse, 1)
+	log.Debugf("looking up IP for mgmt domain=%s", d.SafeString())
+	defer log.Debugf("done looking up IP for mgmt domain=%s", d.SafeString())
+	respChan := make(chan *ipsResponse, 1)

 	go func() {
 		ips, err := net.DefaultResolver.LookupNetIP(ctx, "ip", d.PunycodeString())
-		errChan <- &ipsResponse{
+		respChan <- &ipsResponse{
 			err: err,
 			ips: ips,
 		}
 	}()

 	var resp *ipsResponse

 	select {
 	case <-time.After(dnsTimeout + time.Millisecond*500):
 		log.Warnf("timed out waiting for IP for mgmt domain=%s", d.SafeString())
 		return nil, fmt.Errorf("timed out waiting for ips to be available for domain %s", d.SafeString())
 	case <-ctx.Done():
 		return nil, ctx.Err()
-	case resp = <-errChan:
+	case resp = <-respChan:
 	}
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 011cc81 and 04d8f7c.

📒 Files selected for processing (1)
  • client/internal/dns/mgmt/mgmt.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (13)
  • GitHub Check: Client / Unit
  • GitHub Check: Build Cache
  • GitHub Check: Client / Unit
  • GitHub Check: release_ui_darwin
  • GitHub Check: release
  • GitHub Check: Client / Unit
  • GitHub Check: Android / Build
  • GitHub Check: release_ui
  • GitHub Check: iOS / Build
  • GitHub Check: Darwin
  • GitHub Check: Linux
  • GitHub Check: JS / Lint
  • GitHub Check: Windows
🔇 Additional comments (2)
client/internal/dns/mgmt/mgmt.go (2)

30-34: LGTM!

The struct appropriately encapsulates both the result and error for async channel communication.


108-111: LGTM!

The integration with the new helper function is clean and preserves the existing error-handling behavior.

@sonarqubecloud
Copy link
Copy Markdown

@mlsmaycon mlsmaycon merged commit 433bc4e into main Dec 22, 2025
43 checks passed
@mlsmaycon mlsmaycon deleted the handle-mgmt-dns-cache-timeouts branch December 22, 2025 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants