1
0
mirror of https://github.com/danog/dns.git synced 2025-01-22 13:31:12 +01:00

Fix empty resolution result on too many redirects

Fixes #87.
This commit is contained in:
Patrick Safarov 2019-07-08 22:49:23 +02:00 committed by Niklas Keller
parent 0f59e8a14a
commit 2e7921a13a

View File

@ -153,34 +153,32 @@ final class Rfc1035StubResolver implements Resolver
for ($redirects = 0; $redirects < 5; $redirects++) {
try {
if ($typeRestriction) {
$records = yield $this->query($name, $typeRestriction);
} else {
try {
list(, $records) = yield Promise\some([
$this->query($name, Record::A),
$this->query($name, Record::AAAA),
]);
return yield $this->query($name, $typeRestriction);
}
$records = \array_merge(...$records);
try {
list(, $records) = yield Promise\some([
$this->query($name, Record::A),
$this->query($name, Record::AAAA),
]);
break; // Break redirect loop, otherwise we query the same records 5 times
} catch (MultiReasonException $e) {
$errors = [];
return \array_merge(...$records);
} catch (MultiReasonException $e) {
$errors = [];
foreach ($e->getReasons() as $reason) {
if ($reason instanceof NoRecordException) {
throw $reason;
}
$errors[] = $reason->getMessage();
foreach ($e->getReasons() as $reason) {
if ($reason instanceof NoRecordException) {
throw $reason;
}
throw new DnsException(
"All query attempts failed for {$name}: " . \implode(", ", $errors),
0,
$e
);
$errors[] = $reason->getMessage();
}
throw new DnsException(
"All query attempts failed for {$name}: " . \implode(", ", $errors),
0,
$e
);
}
} catch (NoRecordException $e) {
try {
@ -197,7 +195,7 @@ final class Rfc1035StubResolver implements Resolver
}
}
return $records;
throw new DnsException("Giving up resolution of '{$name}', too many redirects");
});
}