Skip to content

Giving up resolution of 'SMTH', too many redirects #120

@rekryt

Description

@rekryt
<?php

use Amp\Dns\DnsConfig;
use Amp\Dns\DnsConfigLoader;
use Amp\Dns\DnsRecord;
use Amp\Dns\HostLoader;
use Amp\Dns\Rfc1035StubDnsResolver;
use function Amp\Dns\dnsResolver as dnsResolverFactory;

require_once __DIR__ . '/vendor/autoload.php';

$dnsServers = ['1.1.1.1:53'];
$dnsResolver = dnsResolverFactory(
    new Rfc1035StubDnsResolver(
        null,
        new class ($dnsServers) implements DnsConfigLoader {
            public function __construct(private readonly array $dnsServers = []) {
            }

            public function loadConfig(): DnsConfig {
                return new DnsConfig($this->dnsServers, (new HostLoader())->loadHosts());
            }
        }
    )
);

$domain = 'not.existing.domain.com';
try {
    $dnsResolver->resolve($domain, DnsRecord::A);
} catch (Throwable $e) {
    echo $e->getMessage() . PHP_EOL;
}

$domain = 'discord.com';
try {
    $dnsResolver->resolve($domain, DnsRecord::AAAA);
} catch (Throwable $e) {
    echo $e->getMessage() . PHP_EOL;
}
$ php test.php 
Giving up resolution of 'not.existing.domain.com', too many redirects
Giving up resolution of 'discord.com', too many redirects

When no records are retrieved from DNS, the redirect mechanism throws an DnsException.

throw new DnsException("Giving up resolution of '{$name}', too many redirects");

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