Skip to content

dns64: the synthesized AAAA answer carries the A question, so stub resolvers drop it and time out #258

Open

Description

@ShiroiKuma0

With protocol translation on "auto" (PtModeAuto, which rethink-app sets whenever its translation setting is off) and a tunnel that carries both families, the AAAA query of any host that has no AAAA records is answered with a synthesized AAAA — and that answer goes out carrying the A question, not the AAAA one the client asked. Stub resolvers match an answer to their query by id and question, drop it, and wait out their full timeout.

Seen from the user's side: on a dual-stack network every page that touches a v4-only host stalls for seconds to tens of seconds, because getaddrinfo waits for both the A and the AAAA answer. The second lookup of the same host is fine (answered from the alg cache, with the right question), which makes it easy to miss.

Observed on the engine pinned by rethink-app v0.5.8 (d3d530ea3e); the code below is unchanged on n2 HEAD (c2788705).

Where

intra/x64/dns64.go, (*dns64).eval:

ans4, err := d.query64(network, ansin, r, uid)   // the A query the engine makes itself
...
ans64, didTranslate := xdns.TranslateRecords(ans4, dns.TypeA, func(r dns.RR) ...)
...
return ans64

TranslateRecords starts from EmptyResponseFromMessage(ansin) — where its ansin is ans4 — and that copies srcMsg.Question. So ans64 keeps the question of the A query (Request4FromResponse6 sets qname A); the id happens to be right because Request4FromResponse6 copies it. alg.go:q then takes ans64 as ansin and the client gets it as is.

Evidence

The engine's own log shows the query finishing in ~0.3 s:

dns: fwd: 1 for 10190 (fid: 422057297edeb268 / tunnel); query homedepot.com:28 ...
doh: ... q: homedepot.com:28, data: --, code: 0, px: Base, dur: 52ms
dns64: for 10190 over udp: CachePreferred q(homedepot.com.) / a(true) / e(<nil>)
dns64: homedepot.com. for 10190: translated on CachePreferred[CachePreferred] response(1)
alg: q: ok; for ...:homedepot.com:28 ... real: [64:ff9b:1:fffe::23c9:5f53] => subst invalid IP | 64:ff9b:1:da19:100:d63:4bfa:5c2a
dns: fwd: 10 for CachePreferred[10190] (fid: 422057297edeb268) ...

while the client that asked times out:

$ dig @10.111.222.3 +tries=1 +time=6 AAAA lowes.com
;; ;; Question section mismatch: got lowes.com/A/IN
;; communications error to 10.111.222.3#53: timed out

A raw UDP query confirms it: asked bestbuy.com type 28 with id 4660, the reply has id 4660, qd 1 an 1, question bestbuy.com type 1.

First AAAA lookup of fresh v4-only hosts (stackoverflow.com, amazon.com, x.com, twitter.com, duckduckgo.com, ebay.com, imdb.com): no usable answer within 10–25 s; the upstream resolver itself answers the same question in ~0.1 s; the second try through the tunnel answers in ~70 ms. Hosts that do have AAAA records, and DNSSEC-authenticated empty answers (hasauth skips eval), are not affected.

Fix

Restore the question (and id) of the answer being translated before returning it:

if len(ansin.Question) > 0 {
	ans64.Question = append([]dns.Question(nil), ansin.Question...)
	ans64.Id = ansin.Id
}
return ans64

With that, the same first lookups answer in 70–520 ms with type 28 in the question, and dig no longer reports a mismatch. Patch: ShiroiKuma0@cc72988d

Separately, it may be worth not synthesizing at all in PtModeAuto when the network underneath has native IPv4: the client already has (or is about to get) the A answer, and the synthesized address only buys a translated connection to the same place.

Activity

  1. Keridoo commented on Nov 25, 2026

    @Keridoo

    Packet capture confirms it on a plain DNS-only setup, plus a workaround (Rethink v0.5.8)

    Environment

    • Pixel 9, GrapheneOS (Android 17), Rethink v0.5.8 (F-Droid, versionCode 703, arm64-v8a)
    • Mode: DNS only (firewall off), upstream DoH https://dns.quad9.net/dns-query, on-device blocklist enabled, DNS booster on
    • Network settings: "Choose IP version" = Auto, "Perform protocol translations" = on
    • Android Private DNS: automatic (default); Always-on VPN on, lockdown off
    • Underlying network: home Wi-Fi with native IPv6 + DS-Lite; same behaviour on mobile data (464XLAT)

    What the capture shows (Settings → Packet capture → Downloads folder, test host th-koeln.de, which has no AAAA record)

    +14.485 s  query    id=38689  UDP over IPv4  question: th-koeln.de AAAA
    +14.656 s  response id=38689  UDP over IPv4  question: th-koeln.de A      <- question type does not match the query
                                                 answer:   th-koeln.de AAAA 64:ff9b:1:fffe::8b06:ac7 (ttl 2853), plus OPT
    +19.494 s  query    id=38689  UDP over IPv6  question: th-koeln.de AAAA   <- Android retries after 5.0 s on the other resolver address
    +19.520 s  response id=38689  UDP over IPv6  question: th-koeln.de AAAA   <- correct, lookup completes
                                                 answer:   th-koeln.de AAAA 64:ff9b:1:fffe::8b06:ac7 (ttl 2848)
    

    Raw first response: 9721808000010001000000010874682d6b6f656c6e0264650000010001c00c001c000100000b2500100064ff9b0001fffe000000008b060ac700002904d0000000000000

    • Same pattern for 3 of 3 hosts without AAAA in that capture. The control host with a real AAAA record got a response whose question section matched (AAAA) and resolved in about 0.1 s.
    • So the synthesized (DNS64) answer for a v4-only name carries the question of the internal A lookup. Android's resolver drops it and waits for its 5 s timeout. The retry is answered correctly.

    How often it happens (AAAA-only lookups from the shell, ping6 -c 1 <host>, fresh hostnames for every run; hosts without AAAA / control hosts with AAAA)

    Setting stalled ≈ 5.1 s, no AAAA stalled, has AAAA
    IP version Auto, protocol translations on (our normal setup) 8 of 10 0 of 4
    Auto, protocol translations off 9 of 10 0 of 4
    IPv4 & IPv6 (experimental), translations off 7 of 8 0 of 3
    IPv4 & IPv6 (experimental), translations on 7 of 8 0 of 3
    Auto, translations on, DNS booster off 8 of 8 0 of 3
    IPv4 (earlier run) 12 of 20 not separated
    Auto, translations on, "Allowed DNS record types" = Manual without AAAA 0 of 10 0 of 4

    Impact on real apps

    • Six apps force-stopped and started again; counted in Rethink's logcat: hostnames (per app) that were queried again about 5 s later. Normal setup: 10 of 51 names (20 %). Without AAAA: 0 of 43 and 1 of 50.
    • Over a full day on mobile data Android's dumpsys connmetrics reported a mean DNS latency of about 10 s on the VPN network while the underlying network answered in 10–100 ms. Rethink's own DNS log shows all of these lookups as COMPLETE with 12 ms median, so the delay is not visible in the app.
    • Brave/Chromium is not affected (own resolver, does not wait for AAAA).

    Workaround until a fix ships

    • DNS → "Allowed DNS record types" → Manual, uncheck AAAA. AAAA lookups then fail fast (about 90 ms) and no lookup stalls, on Wi-Fi and on mobile data. The price is that no IPv6 destination can be resolved.

    Questions

    • Is the question section of the synthesized answer meant to be rewritten to the original AAAA question? The second path (retry over IPv6, probably served from the cache) already does it.
    • Is there a way to switch off the synthesis alone? Neither "Choose IP version" nor "Perform protocol translations" changed it here.

    I can share the pcap (about 6 kB, only the test lookups are relevant) if that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions