Skip to content

Incorrect error handling for NXDOMAIN #77

@LeifOfWilsonCreek

Description

@LeifOfWilsonCreek

When receiving the response NXDOMAIN, AsyncDNSResolver throws .internalError, requiring callers to code like this:

        var records: [SRVRecord]
        do {
            records = try await Self.resolver.querySRV(name: srvName)
        } catch let error as AsyncDNSResolver.Error where error.code == .internalError {
            // Catch NXDOMAIN, which is erroneously reported as `.internalError`.
            // NXDOMAIN and `results==[]` (commonly called "NODATA") both indicate affirmative nonexistence.
            // Hopefully other common errors aren't `.internalError` as that may cause weird behavior here.
            records = []
        } catch let error {
            // Catch timeouts and other transient network errors.
            throw error
        }

Adding an exception for .nxDomain might be a tempting solution, but it would break existing workarounds like the above. But it can't be conflated into .internalError; doing so as it does now is clearly a bug.

I suggest updating queryXXX calls to return [] when the response is coded NXDOMAIN. This makes sense because the distinction between the DNS entry existing only by different types (commonly "NODATA") vs not existing at all (NXDOMAIN) isn't a useful distinction, so they can be treated the same. Returning [] simplifies clients by not needing the first catch case shown above, and sidesteps potential compatibility issues for existing callers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions