mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-24 15:56:40 +00:00
Fix .local
dns resolution when returning multiple addresses
The supervisor performs its own local resolution for `.local` addresses due to a limitation in [musl](https://wiki.musl-libc.org/future-ideas.html). The resolution function was not following exactly the nodejs [dns.lookup specification](https://nodejs.org/api/dns.html#dnslookuphostname-options-callback) which could cause certain clients to fail (in this case happy-eyeballs). This updates the function to follow the specification. Change-type: patch
This commit is contained in:
parent
52b47b91f0
commit
39c667803d
20
src/app.ts
20
src/app.ts
@ -11,7 +11,10 @@ class DnsLookupError extends Error {
|
|||||||
interface DnsLookupCallback {
|
interface DnsLookupCallback {
|
||||||
(err: any): void;
|
(err: any): void;
|
||||||
(err: undefined | null, address: string, family: number): void;
|
(err: undefined | null, address: string, family: number): void;
|
||||||
(err: undefined | null, addresses: string[]): void;
|
(
|
||||||
|
err: undefined | null,
|
||||||
|
addresses: Array<{ address: string; family: number }>,
|
||||||
|
): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface DnsLookupOpts {
|
interface DnsLookupOpts {
|
||||||
@ -75,9 +78,9 @@ interface DnsLookupOpts {
|
|||||||
.catch(() => {
|
.catch(() => {
|
||||||
return '';
|
return '';
|
||||||
})
|
})
|
||||||
.then((addr) => {
|
.then((address) => {
|
||||||
return {
|
return {
|
||||||
addr,
|
address,
|
||||||
family,
|
family,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@ -87,7 +90,7 @@ interface DnsLookupOpts {
|
|||||||
// resolve the addresses...
|
// resolve the addresses...
|
||||||
return Promise.all(getResolvers()).then((results) => {
|
return Promise.all(getResolvers()).then((results) => {
|
||||||
// remove any that didn't resolve...
|
// remove any that didn't resolve...
|
||||||
let allAddresses = results.filter((result) => result.addr !== '');
|
let allAddresses = results.filter((result) => result.address !== '');
|
||||||
|
|
||||||
// unless the results should be returned verbatim, sort them so v4 comes first...
|
// unless the results should be returned verbatim, sort them so v4 comes first...
|
||||||
if (opts && typeof opts !== 'number' && !opts.verbatim) {
|
if (opts && typeof opts !== 'number' && !opts.verbatim) {
|
||||||
@ -102,15 +105,12 @@ interface DnsLookupOpts {
|
|||||||
|
|
||||||
// all the addresses were requested...
|
// all the addresses were requested...
|
||||||
if (opts && typeof opts !== 'number' && opts.all) {
|
if (opts && typeof opts !== 'number' && opts.all) {
|
||||||
return cb(
|
return cb(null, allAddresses);
|
||||||
null,
|
|
||||||
allAddresses.map((r) => r.addr),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// only a single address was requested...
|
// only a single address was requested...
|
||||||
const [{ addr, family }] = allAddresses;
|
const [{ address, family }] = allAddresses;
|
||||||
return cb(null, addr, family);
|
return cb(null, address, family);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user