apple / swift-async-dns-resolver

A Swift library for asynchronous DNS requests, wrapping c-ares with Swift-friendly APIs and data structures.
Apache License 2.0
82 stars 12 forks source link

DNSSD based queries are incomplete #38

Open gmilos opened 1 month ago

gmilos commented 1 month ago

On macOS (where DNSSD is being used by default), queries for domains with multiple records, such as:

AsyncDNSResolver().queryAAAA(name: "iadsdk.apple.com.akadns.net")

normally return the two AAAA records associated with the domain. However, occasionally, only one is returned. It happens at roughly 1% of the time in my tests, but since this is a race, that number will fluctuate with the different timing conditions.

The core reason for this is that the library calls DNSServiceProcessResult precisely once. The callbacks are delivered as a result of this call, but DNSSD offers no guarantees about how many records will get provided per DNSServiceProcessResult invocation.

Additionally, while DNSSD provides kDNSServiceFlagsMoreComing, the flag is designed to reduce unnecessary UI updates only. It'd be fragile to use attach additional semantics to it.