Use custom fallback DNS servers

This commit is contained in:
Fedor Indutny 2023-03-22 13:56:49 -07:00 committed by GitHub
parent 56145fabcc
commit 2f691f3dd0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,13 +1,22 @@
// Copyright 2023 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { lookup as nativeLookup, resolve4, resolve6 } from 'dns';
import {
lookup as nativeLookup,
resolve4,
resolve6,
getServers,
setServers,
} from 'dns';
import type { LookupOneOptions } from 'dns';
import * as log from '../logging/log';
import * as Errors from '../types/errors';
import { strictAssert } from './assert';
const ORIGINAL_SERVERS = getServers();
const FALLBACK_SERVERS = ['1.1.1.1'];
export function lookupWithFallback(
hostname: string,
opts: LookupOneOptions,
@ -37,6 +46,7 @@ export function lookupWithFallback(
fallbackErr: NodeJS.ErrnoException | null,
records: Array<string>
): void => {
setServers(ORIGINAL_SERVERS);
if (fallbackErr) {
return callback(fallbackErr, '', 0);
}
@ -53,6 +63,7 @@ export function lookupWithFallback(
callback(null, records[index], family);
};
setServers(FALLBACK_SERVERS);
if (family === 4) {
resolve4(hostname, onRecords);
} else {