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

Add redundancy, remove https option, add onlyHttps option… #34

Merged
merged 16 commits into from
Nov 22, 2019

Conversation

ghostnumber7
Copy link
Contributor

@ghostnumber7 ghostnumber7 commented Aug 25, 2019

Some things that could be considered to be useful:

  • Multiple DNS resolver host alternatives
  • Multiple DNS resolver providers
  • Fallback to HTTPS by default if DNS does not resolve (no need to choose one or the other, just try DNS and if it fails use HTTPS)
  • Ability to disable or enable HTTPS check ({ https: true } will only check HTTPS). Defaults to DNS + HTTPS
  • Added options.urls array to be able to add more urls to fallback to (like ifconfig.co)

@sindresorhus
Copy link
Owner

DNS resolver hosts by host name not IP

Why? The IP address will not change anyway. Resolving to the IP adds a slight overhead.

Multiple DNS resolver host alternatives
Multiple DNS resolver providers

Good idea. This should be documented in the readme.

Fallback to HTTPS by default if DNS does not resolve (no need to choose one or the other, just try DNS and if it fails use HTTPS)

👍

I don't really see the needs for a dns option though. I'm thinking the default behavior would be DNS + HTTPS fallback, and an option to force only HTTPS.

Added options.urls array to be able to add more urls to fallback to (like ifconfig.co)

👍


These changes will need tests and readme updates.

index.js Outdated Show resolved Hide resolved
index.js Outdated
data.dnsServers.forEach(dnsServerInfo => {
const {servers, question} = dnsServerInfo;
servers.forEach(server => {
// eslint-disable-next-line promise/prefer-await-to-then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rule is there for a reason. There's never a case where you have to use .then.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to do a for-in loop with await but linter was not happy with it ... in this case, I chain then after then so that they run concurrently to simulate a for loop with await inside ... maybe there's a better approach I'm not seeing

index.js Outdated Show resolved Hide resolved
@ghostnumber7
Copy link
Contributor Author

NS resolver hosts by host name not IP

Why? The IP address will not change anyway. Resolving to the IP adds a slight overhead.

Don't think overhead is relevant in this case. Thought about using hostnames when I realized that I couldn't find 2620:0:ccc::2 by digging any of the opendns resolvers. They may not change, but it made me doubt xD

@ghostnumber7
Copy link
Contributor Author

ghostnumber7 commented Aug 26, 2019

I'm also thinking about randomizing the order in which dns hosts are checked to minimize the chance of going multiple times to one that's having problems before going to others ... what do you think?

@ghostnumber7
Copy link
Contributor Author

ghostnumber7 commented Aug 26, 2019

Changes in last commit:

  • removed forEach in favour of for-of
  • added tests for new features
  • added stubs to control flow failures
  • documented things (I think my documentation skills are terrible so feel free to improve)

Pending:

  • Using ips instead of hostnames for DNS resolvers (probably :P)
  • Randomizing DNS resolve order?
  • Making changes on browser file to behave the same way?

@sindresorhus
Copy link
Owner

I don't really see the needs for a dns option though. I'm thinking the default behavior would be DNS + HTTPS fallback, and an option to force only HTTPS.

⬆️

@sindresorhus
Copy link
Owner

Using ips instead of hostnames for DNS resolvers (probably :P)

I don't see any downside with it.

Randomizing DNS resolve order?

👍 Good idea!

Making changes on browser file to behave the same way?

👍

package.json Outdated
@@ -13,7 +13,7 @@
"node": ">=8"
},
"scripts": {
"test": "xo && ava test.js && tsd"
"test": "xo && ava -s test.js && tsd"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the AVA package.json config instead of the CLI flag.

readme.md Outdated

##### urls

Type: `array`<br>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Type: `array`<br>
Type: `string[]`<br>

readme.md Outdated Show resolved Hide resolved
test.js Outdated Show resolved Hide resolved
test.js Outdated Show resolved Hide resolved
mocks/dns-socket.js Outdated Show resolved Hide resolved
mocks/got.js Outdated
ignoreRegExp = undefined;
ignored = [];
called = 0;
};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there really no less verbose way to do the mocking?

@ghostnumber7
Copy link
Contributor Author

So ... did your suggestions, mocked in a less verbose way (don't know if I can make it better, I normally use jest instead of ava+sinon so to be honest, I have no idea what I'm doing XD). Removed the -s option on ava CLI call, but there is no option in package.json ava config to do the same, so had to add serial to every test. Also, ava is bad at handling async stubbing, so we either have every test on its own file, or we run serially (avajs/ava#1066)
Did changes on browser file also.
Did find one downside to using ipv6 ip instead of hostnames for dns resolving: When you don't have ipv6 it would normally just fail to find your ipv6 ip when resolving via host name, but when using ipv6 ip, it times out instead, and is it's making 6 checks, it takes 30 seconds for that to happen on default config. I guess it would not be a problem because you will be using it when you know you have an ipv6 enabled network.
DNS option has been removed in previous commit, I updated the first comment now to reflect that.
I didn't do the randomizing on the DNS order ... maybe we can add a TODO comment somewhere and have it done at some other time :P

@sindresorhus
Copy link
Owner

but there is no option in package.json ava config to do the same

There is. See the serial setting. You can also do it for a single file by using the import import {serial as test} from 'ava';

Also, ava is bad at handling async stubbing, so we either have every test on its own file, or we run serially (avajs/ava#1066)

The problem is neither AVA nor async, but rather concurrency. Stubbing is incompatible with concurrency.

I didn't do the randomizing on the DNS order ... maybe we can add a TODO comment somewhere and have it done at some other time :P

Can you open an issue about it? TODO comments are code rot.

@sindresorhus
Copy link
Owner

I don't really see the needs for a dns option though. I'm thinking the default behavior would be DNS + HTTPS fallback, and an option to force only HTTPS.

⬆️

This is not implemented. There should only be a boolean (no null) option. Maybe called onlyHttps.

index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
test.js Outdated Show resolved Hide resolved
test.js Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
@ghostnumber7
Copy link
Contributor Author

I don't really see the needs for a dns option though. I'm thinking the default behavior would be DNS + HTTPS fallback, and an option to force only HTTPS.

⬆️

This is not implemented. There should only be a boolean (no null) option. Maybe called onlyHttps.

changed to onlyHttps default false

@sindresorhus
Copy link
Owner

Did you see #40? I think we should remove icanhazip.com. But that leaves us with only ipify.org for the browser. Do you know any other free IP service that works over HTTPS?

index.d.ts Outdated Show resolved Hide resolved
index.d.ts Outdated Show resolved Hide resolved
index.d.ts Outdated Show resolved Hide resolved
index.d.ts Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
test.js Outdated Show resolved Hide resolved
mocks/stub.js Outdated Show resolved Hide resolved
mocks/stub.js Outdated Show resolved Hide resolved
browser.js Outdated Show resolved Hide resolved
browser.js Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
@sindresorhus sindresorhus changed the title Multiple DNS and HTTPS retries & HTTPS fallback when DNS fails Add redundancy, remove https option, add onlyHttps option, add fallbackUrls option Nov 22, 2019
@sindresorhus sindresorhus changed the title Add redundancy, remove https option, add onlyHttps option, add fallbackUrls option Add redundancy, remove https option, add onlyHttps option… Nov 22, 2019
@sindresorhus sindresorhus merged commit fdcbb7d into sindresorhus:master Nov 22, 2019
@sindresorhus
Copy link
Owner

Very nice! Thanks for working on this 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants