Skip to content

Commit 914c1ba

Browse files
committed
silenced DNS query exceptions
1 parent 89cb777 commit 914c1ba

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/Common/DNSAddressResolver.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use const DNS_AAAA;
2020
use function dns_get_record;
2121
use Laudis\Neo4j\Contracts\AddressResolverInterface;
22+
use Throwable;
2223

2324
class DNSAddressResolver implements AddressResolverInterface
2425
{
@@ -31,8 +32,13 @@ public function getAddresses(string $host): iterable
3132
// as late as possible
3233
yield $host;
3334

34-
/** @var list<array{ip?: string|null}> $records */
35-
$records = dns_get_record($host, DNS_A | DNS_AAAA);
35+
try {
36+
/** @var list<array{ip?: string|null}> $records */
37+
$records = dns_get_record($host, DNS_A | DNS_AAAA);
38+
} catch (Throwable $e) {
39+
$records = []; // Failed DNS queries should not halt execution
40+
}
41+
3642
if (count($records) === 0) {
3743
yield from $this->tryReverseLookup($host);
3844
} else {
@@ -47,8 +53,13 @@ public function getAddresses(string $host): iterable
4753
*/
4854
private function tryReverseLookup(string $host): iterable
4955
{
50-
/** @var list<array{target?: string|null}> $records */
51-
$records = dns_get_record($host.'.in-addr.arpa');
56+
try {
57+
/** @var list<array{target?: string|null}> $records */
58+
$records = dns_get_record($host.'.in-addr.arpa');
59+
} catch (Throwable $e) {
60+
$records = []; // Failed DNS queries should not halt execution
61+
}
62+
5263
if (count($records) !== 0) {
5364
$records = array_map(static fn (array $x) => $x['target'] ?? '', $records);
5465
$records = array_filter($records, static fn (string $x) => $x !== '');

0 commit comments

Comments
 (0)