Got: `dnsCache: true` has no effect

Created on 23 Jul 2020  路  14Comments  路  Source: sindresorhus/got

Describe the bug

  • Node.js version: v12.16.1
  • OS & version: OSX 10.14.6

I'm trying to enable DNS cache for my app but looking at the DNS requests using tcdump the DNS TTL isn't respected.

Actual behavior

DNS TTL isn't respected

Expected behavior

DNS TTL is respected

Code to reproduce

npm install got

const got = require('got');
setInterval(() => {
 got('https://google.com',{dnsCache: true}).then(response =>{
        console.log(`${response.body},`);
  });
}, 1000);

you can see the DNS requests going on using tcpdump:

tcpdump -i any -A  -vv port 53

Checklist

  • [x] I have read the documentation.
  • [x] I have tried my code with the latest version of Node.js and Got.
bug

All 14 comments

we have such bug in our applications

I think one workaround would be to provide your own CacheableLookup instance.

import got from 'got';
import CacheableLookup from 'cacheable-lookup';

const dnsCache = new CacheableLookup();

setInterval(() => {
 got('https://google.com', { dnsCache }).then(response =>{
        console.log(`${response.body},`);
  });
}, 1000);

Thank you @known-as-bmf the workaround seems to work, but i'd like to see this fixed in got as well.
Any maintainers looking at this issue? @sindresorhus @szmarczak ?

I'll look at this later today.

const instance = got.extend({dnsCache: true});

instance('https://google.com').then(response =>{
    console.log(`${response.body.length}`);
});

Works. So that means got('https://google.com', {dnsCache: true}) generates a new CacheableLookup instance every time. Fixing this now.

This also causes a memory leak. Good spot!

@szmarczak thank you fixing this when can we have a release with the fix in it?

I'll do one tomorrow.

@szmarczak sorry to bug you further, is there anything that is blocking a tag release?

Sorry it took so long. Released 11.5.2.

Thank you @szmarczak !

I got your email. I'm pretty sure I made also an NPM release... Weird, I access publish anymore and when I try to log in it loads indefinitely.

@sindresorhus Can you try to publish a new NPM version (11.5.2)?

@szmarczak Done. I think it failed because npm had some downtime.

thank you @sindresorhus and @szmarczak !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lukechu10 picture lukechu10  路  3Comments

jamestalmage picture jamestalmage  路  3Comments

khizarsonu picture khizarsonu  路  3Comments

tkoelpin picture tkoelpin  路  3Comments

alanzhaonys picture alanzhaonys  路  4Comments