Skip to content

fix(dns): keep one copy of identical records in a zone - #14371

Merged
HarshMN2345 merged 3 commits into
mainfrom
fix/dns-zone-duplicate-records
Oct 23, 2026
Merged

HarshMN2345 merged 3 commits into
mainfrom
fix/dns-zone-duplicate-records

Conversation

@HarshMN2345

@HarshMN2345 HarshMN2345 commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

A Zone built with the same record twice answered every lookup with both copies. RFC 2181 §5 says servers should suppress records whose name, class, type and data are all equal. Some clients treat a doubled answer as an error: a certificate authority, for example, reads two identical CAA records as a conflict.

Zone now keeps one copy of each identical record. Records count as identical when they share name, type, class, rdata, priority, weight and port; an unset priority, weight or port counts as 0, the value it is encoded as. TTL is not compared: the copy kept has the lowest TTL among them, as RFC 2181 §5.2 has an RRset take, and it stays where the first copy was. Lookups, wildcard synthesis and File::export therefore all work on a clean set. $records is no longer a promoted property, so the constructor can assign the deduplicated list.

The rdata is compared as written. File::import already writes target names lowercase and without a trailing dot; records built directly with a target in another case or with a trailing dot are not matched.

Test Plan

  • ZoneTest::testConstructorKeepsOneCopyOfIdenticalRecords:
    • copies that differ only in name case or TTL collapse to one, and the copy with the lowest TTL is kept in the first copy's place;
    • an MX with no priority collapses with the same MX at priority 0;
    • records with a different rdata or MX priority stay.
  • ResolverTest::testLookupAnswersIdenticalRecordsOnce: an exact CAA lookup and a wildcard CNAME synthesis each return one answer.
  • Both new tests fail on main and pass on this branch.
  • The Zone, Resolver and File tests pass (76 tests).
  • Pint and Rector pass. PHPStan (the package's level max) reports nothing in the changed files.

Related PRs and Issues

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs? (N/A)

A zone holding the same record twice answered with both copies.
RFC 2181 section 5 says servers should suppress records whose name,
class, type and data are all equal, and some CAs read a doubled CAA
answer as a conflict. Zone now keeps the first of each identical
record, so every lookup and export works on a clean set.
@luxor-code-review

luxor-code-review Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Review complete. 🟡 1 medium

💬 Inline comments (1)

  • 🟡 Dedup keeps first-seen TTL, not the lowest — Zone.php:53

This PR makes packages/dns/src/Zone.php deduplicate records with identical name, type, and rdata, matching RFC 2181 RRset semantics and dropping duplicate TTL variants via first-wins selection. Tests in packages/dns/tests/ZoneTest.php and packages/dns/tests/Zone/ResolverTest.php cover the new behavior.

Files Change
packages/dns/src/Zone.php Dedupes records in the constructor using a name/type/rdata key with array_values reindexing
packages/dns/tests/ZoneTest.php Adds tests for duplicate record removal in the constructor
packages/dns/tests/Zone/ResolverTest.php Adds resolver-path tests exercising dedup behavior

Reviewed commit: 1fdbab0

@ghost

ghost commented Oct 12, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The newest changes are a comment and formatting-only refactor, with no behavior defect found.

Zone construction now keeps one copy of identical DNS records, retaining the lowest TTL while leaving records in their original first-occurrence order. Resolver lookups, wildcard synthesis, and zone-file export use the deduplicated records; regression tests cover constructor behavior and exact and wildcard answers.

Latest changes: The newest commit moves and clarifies the deduplication comment beside its key and reformats the key fields across multiple lines without changing behavior.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 3
File Change
packages/dns/src/Zone.php Deduplicates zone records and retains the lowest-TTL copy; the latest commit clarifies the adjacent comment and reformats the key.
packages/dns/tests/ZoneTest.php Covers duplicate record handling, TTL selection, and record differences.
packages/dns/tests/Zone/ResolverTest.php Checks exact and wildcard resolver answers contain duplicates only once.

Reviewed the commits since 406ffa6 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Tier A · See the inline comments. Summary

Comment thread packages/dns/src/Zone.php Resolved
@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

6 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (3)
  • php.appwrite.secret-compare-timing (1)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@luxor-code-review luxor-code-review Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Adds TTL-agnostic duplicate-record deduplication to the DNS Zone constructor, keyed on name/type/rdata.

Key findings

  • 🟡 Dedup keeps first-seen TTL, not the lowest — Zone.php:53

Comment thread packages/dns/src/Zone.php Resolved
RFC 2181 section 5.2 has every record of an RRset take the lowest TTL
among them, so the copy kept now carries it, in the place of the first
copy. An MX or SRV field left unset is encoded as 0, so it now matches
an explicit 0.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Tier S · Looks good to merge. Summary

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/dns-zone-duplicate-records (after).

Metric Before After Change
🚀 Requests/sec 217.96 223.6 ⚪ +2.6%
⏱️ Latency P50 78.9 ms 78.46 ms ⚪ -0.6%
⏱️ Latency P95 184.71 ms 176.92 ms ⚪ -4.2%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 78.46 176.92 13,680 223.6 -7.79
Account 148.96 273.9 720 12.44 -7.02
TablesDB 77.8 145.31 7,440 124.08 +3.5
Storage 69 159.33 3,600 62.02 +6.59
Functions 106.31 199.65 1,920 33.78 -30.07

Top API waits (after)

API request Max wait (ms)
account.name.update 372.27
functions.create 370.24
functions.variables.create 364.04
account.prefs.update 361.12
account.get 345.69

The zone check keeps its original comment, the dedupe gets its own, and the
key lists one field per line. No behaviour change.
@HarshMN2345
HarshMN2345 merged commit b2be52c into main Oct 23, 2026
9 checks passed
Tapraj-Pathak pushed a commit to Tapraj-Pathak/appwrite that referenced this pull request Oct 24, 2026
…e-records

fix(dns): keep one copy of identical records in a zone

(cherry picked from commit b2be52c)
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.

1 participant