diff --git a/lib/interceptor/dns.js b/lib/interceptor/dns.js index f1caeef3001..e0e1d7fa486 100644 --- a/lib/interceptor/dns.js +++ b/lib/interceptor/dns.js @@ -66,7 +66,7 @@ class DNSInstance { !newOpts.dualStack && newOpts.affinity ) - return cb( + cb( null, `${origin.protocol}//${ ip.family === 6 ? `[${ip.address}]` : ip.address @@ -75,10 +75,9 @@ class DNSInstance { }) } else { // If there's IPs we pick - const records = this.#records.get(origin.hostname) const ip = this.pick( origin, - records, + ips, // Only set affinity if dual stack is disabled // otherwise let it go through normal flow !newOpts.dualStack && newOpts.affinity @@ -109,22 +108,21 @@ class DNSInstance { return cb(err) } - const results = [] + const results = new Map() for (const addr of addresses) { const record = { address: addr.address, - ttl: - addr.ttl != null - ? Math.min(addr.ttl * 1000, this.#maxTTL) - : this.#maxTTL, + ttl: opts.maxTTL, family: addr.family } - results.push(record) + // On linux we found duplicates, we attempt to remove them with + // the latest record + results.set(`${record.address}:${record.family}`, record) } - cb(null, results) + cb(null, results.values()) } ) } diff --git a/test/interceptors/dns.js b/test/interceptors/dns.js index a63cf5f4c13..bca94757556 100644 --- a/test/interceptors/dns.js +++ b/test/interceptors/dns.js @@ -543,7 +543,7 @@ test('Should we handle TTL (4)', async t => { return cb(err) } - const results = [] + const results = new Map() for (const addr of addresses) { const record = { @@ -552,10 +552,10 @@ test('Should we handle TTL (4)', async t => { family: addr.family } - results.push(record) + results.set(`${record.address}:${record.family}`, record) } - cb(null, results) + cb(null, results.values()) } ) }