Skip to content

chore: allow using v4 over v6 for resolved dns results#237

Merged
ggazzo merged 2 commits intomainfrom
fix/iporder
Sep 30, 2025
Merged

chore: allow using v4 over v6 for resolved dns results#237
ggazzo merged 2 commits intomainfrom
fix/iporder

Conversation

@debdutdeb
Copy link
Member

@debdutdeb debdutdeb commented Sep 30, 2025

Summary by CodeRabbit

  • New Features
    • Added a configurable DNS lookup order via environment variable to improve connectivity across diverse network environments.
    • Supports IPv4-first, IPv6-first, or verbatim resolution; retains existing default when unset or invalid.
    • Allows administrators to adjust name-resolution behavior without code changes, potentially reducing connection delays and improving reliability.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 30, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Added an environment-configurable DNS lookup order to the federation resolver (default: ipv6first). The resolver reads and validates HOMESERVER_CONFIG_DNS_LOOKUP_ORDER at construction, applies the order to DNS lookups, and exports a singleton resolver instance.

Changes

Cohort / File(s) Change Summary
Server discovery resolver
packages/federation-sdk/src/server-discovery/_resolver.ts
Added private lookupOrder: LookupAllOptions['order'] with default 'ipv6first'; read and validate HOMESERVER_CONFIG_DNS_LOOKUP_ORDER (`'ipv4first'

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Env as Environment
    participant App as App Startup
    participant Res as _Resolver (singleton)
    participant DNS as DNS

    note over App,Res: Initialization
    App->>Env: read HOMESERVER_CONFIG_DNS_LOOKUP_ORDER
    App->>Res: new _Resolver()
    Res->>Res: validate env ∈ {ipv4first, ipv6first, verbatim}
    Res->>Res: set lookupOrder (default: ipv6first)

    note over App,Res: Runtime resolution
    App->>Res: resolve(host)
    Res->>DNS: dns.lookup(host, { all: true, order: lookupOrder })
    DNS-->>Res: addresses ordered per lookupOrder
    Res-->>App: resolved addresses
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • rodrigok

Poem

Whiskers twitch at dawn’s first byte,
I flip the bits from left to right—
IPv6 skies or IPv4 light,
Env winds steer my routing flight.
Hop, resolve, then sleep tonight. 🥕🐇

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title accurately summarizes the primary enhancement—allowing IPv4 to be preferred over IPv6 in DNS resolution—without extraneous detail or noise, and it is concise and clear.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2b36eb0 and abbce1f.

📒 Files selected for processing (1)
  • packages/federation-sdk/src/server-discovery/_resolver.ts (3 hunks)

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
🧪 Early access (Sonnet 4.5): enabled

We are currently testing the Sonnet 4.5 model, which is expected to improve code review quality. However, this model may lead to increased noise levels in the review comments. Please disable the early access features if the noise level causes any inconvenience.

Note:

  • Public repositories are always opted into early access features.
  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.

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

@codecov-commenter
Copy link

codecov-commenter commented Sep 30, 2025

Codecov Report

❌ Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.86%. Comparing base (5d5e8f5) to head (abbce1f).

Files with missing lines Patch % Lines
...s/federation-sdk/src/server-discovery/_resolver.ts 80.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #237      +/-   ##
==========================================
+ Coverage   81.76%   81.86%   +0.09%     
==========================================
  Files          63       63              
  Lines        4701     4709       +8     
==========================================
+ Hits         3844     3855      +11     
+ Misses        857      854       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
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)
packages/federation-sdk/src/server-discovery/_resolver.ts (1)

19-30: Consider refactoring for improved type safety.

The environment variable reading and validation logic works correctly, but the type assertion on lines 22-23 bypasses TypeScript's type checking. While the subsequent validation catches invalid values, consider using a type guard for better type safety:

-		const order = process.env
-			.HOMESERVER_CONFIG_DNS_LOOKUP_ORDER as typeof this.lookupOrder;
-		if (
-			order === 'ipv4first' ||
-			order === 'ipv6first' ||
-			order === 'verbatim'
-		) {
+		const order = process.env.HOMESERVER_CONFIG_DNS_LOOKUP_ORDER;
+		if (order && (
+			order === 'ipv4first' ||
+			order === 'ipv6first' ||
+			order === 'verbatim'
+		)) {
 			this.lookupOrder = order;
 		}

This removes the type assertion and adds an explicit undefined check, making the code more explicit about its intent.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 5d5e8f5 and 2b36eb0.

📒 Files selected for processing (1)
  • packages/federation-sdk/src/server-discovery/_resolver.ts (3 hunks)
🔇 Additional comments (4)
packages/federation-sdk/src/server-discovery/_resolver.ts (4)

1-1: LGTM!

The import of LookupAllOptions type properly supports the new configurable lookup order feature.


6-6: LGTM!

The private member with a default of 'ipv6first' preserves existing behavior while enabling configuration.


39-39: LGTM!

The method now correctly applies the configurable lookup order instead of the hardcoded value.


46-46: Approve singleton resolver export.

No other _Resolver instantiations or imports were found; using this shared resolver instance ensures consistent behavior across the application.

@ggazzo ggazzo merged commit 3c8e367 into main Sep 30, 2025
2 of 3 checks passed
@ggazzo ggazzo deleted the fix/iporder branch September 30, 2025 12:33
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.

3 participants