-
-
Notifications
You must be signed in to change notification settings - Fork 957
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
Instantiate CacheableLookup only when needed #1529
Instantiate CacheableLookup only when needed #1529
Conversation
The `dnsCache` option is disabled by default but a `CacheableLookup` instance is always created. The proposed change is to instantiate CacheableLookup only when needed, which may make `got` a bit faster to load by default and when you do not use the DNS cache. Moreover, the CacheableLookup class instantiates the DNS [`Resolver` class in NodeJS the standard library](https://nodejs.org/api/dns.html#dns_class_dnspromises_resolver), and the test framework [Jest](https://github.com/facebook/jest/) has a problem with it. It wrongly detects that something keeps running after the tests are finished, while it's just an instance of the DNS Resolver class. See jestjs/jest#6423 Jest should be fixed but meanwhile this small improvement in got may also hide the Jest issue for many developers.
It looks like the tests succeed excepts with Node 12. But I'm not sure it's related to the changes in this pull request. The last commit on the master branch was also failing on Node 12 : https://github.com/sindresorhus/got/runs/1342216844 |
This will cause the |
Are you sure ? I think it will be generated only the first time. It's still a global instance, just not initialized before it's used. |
|
I'm sure. |
I understand you don't want to create one instance for each call, and this test is still successful with my suggested modification. https://travis-ci.com/github/sindresorhus/got/jobs/443599127 |
Ah, I see now. I didn't notice the |
No problems, I understand why you were suspicious. Many thanks for the merge! |
Thanks to you for the PR! Never underestimate your work :) |
Could we get a release cut of |
No, there is v11 already and v12 is pending. |
We decided to back port it: https://github.com/sindresorhus/got/releases/tag/v11.8.2 |
The
dnsCache
option is disabled by default but aCacheableLookup
instance is always created. The proposed change is to instantiate CacheableLookup only when needed, which may makegot
a bit faster to load by default and when you do not use the DNS cache.Moreover, the CacheableLookup class instantiates the DNS
Resolver
class in NodeJS the standard library, and the test framework Jest has a problem with it. It wrongly detects that something keeps running after the tests are finished, while it's just an instance of the DNS Resolver class. See jestjs/jest#6423Jest should be fixed but meanwhile this small improvement in got may also hide the Jest issue for many developers.
Checklist