Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dnsCache: true has no effect #1372

Closed
2 tasks done
ltagliamonte-dd opened this issue Jul 22, 2020 · 14 comments
Closed
2 tasks done

dnsCache: true has no effect #1372

ltagliamonte-dd opened this issue Jul 22, 2020 · 14 comments
Labels
bug Something does not work as it should

Comments

@ltagliamonte-dd
Copy link

ltagliamonte-dd commented Jul 22, 2020

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

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Got.
@alexvlasoff
Copy link

we have such bug in our applications

@known-as-bmf
Copy link

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);

@ltagliamonte-dd
Copy link
Author

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 ?

@szmarczak
Copy link
Collaborator

I'll look at this later today.

@szmarczak szmarczak changed the title DNS cache not working dnsCache: true has no effect Jul 28, 2020
@szmarczak szmarczak added the bug Something does not work as it should label Jul 28, 2020
@szmarczak
Copy link
Collaborator

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.

@szmarczak
Copy link
Collaborator

This also causes a memory leak. Good spot!

@ltagliamonte-dd
Copy link
Author

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

@szmarczak
Copy link
Collaborator

I'll do one tomorrow.

@ltagliamonte-dd
Copy link
Author

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

@szmarczak
Copy link
Collaborator

Sorry it took so long. Released 11.5.2.

@ltagliamonte-dd
Copy link
Author

Thank you @szmarczak !

@szmarczak
Copy link
Collaborator

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)?

@sindresorhus
Copy link
Owner

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

@ltagliamonte-dd
Copy link
Author

thank you @sindresorhus and @szmarczak !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something does not work as it should
Projects
None yet
Development

No branches or pull requests

5 participants