Skip to content

-rate still under-counts wire queries: CNAME sends 3 queries and Go's resolver retries internally #50

Closed

Description

@TMHSDigital

Why it matters

#32 made -rate and -max-queries reserve per wire query, and the README now promises -rate is "max DNS queries per second on the wire ... including every record type, retry, wildcard probe and the preflight". Two gaps remain, and both overshoot the limit precisely when a resolver is struggling, which is when users rely on -rate to avoid bans.

Evidence

  1. CNAME is charged 2 slots but sends 3 queries. In Go 1.24, net.Resolver.LookupCNAME issues A, AAAA and CNAME queries. See internal/dns/resolver.go:122 (queriesPerType). Repro: 3 wire queries, 2 slots charged.
  2. Retries inside the Go resolver are never charged. tryOneName loops attempts(2) × len(system nameservers) on SERVFAIL, REFUSED or socket errors. The custom Dial (resolver.go:142-146) sends every one of those to -dns-server.
    • Repro: one SERVFAIL A lookup put 4 queries on the wire and was charged 1 slot.
    • With -attempts 3, the same lookup put 12 on the wire and was charged 3.
    • The multiplier depends on the host's resolv.conf.
  3. Related limits of the stdlib client.
    • RCODE REFUSED is reported as "server misbehaving" and counted as OutcomeOther, so the "refused" stat never reflects the most common rate-limit signal (resolver.go:62).
    • Error text names the system nameserver instead of the configured -dns-server.

Suggested approach

  • Short term:
    • Set CNAME's cost to 3.
    • In the Dial hook, reserve a rate slot for every dial beyond the pre-reserved count. Each Go exchange dials a fresh connection, so dials equal queries.
  • Long term (recommended): move to a DNS client with one server and an explicit attempt count, such as github.com/miekg/dns. That gives exact accounting, real RCODEs (REFUSED, SERVFAIL), correct error text, and simpler tests.

Done when

  • A test asserts that wire queries equal charged slots for each record type, including under SERVFAIL.
  • REFUSED responses are counted as refused.

Activity

  1. added
    bug
    priority: medium
    area: dns
    on Oct 4, 2026
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

    area: dnsbugpriority: medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions