timeout options doesn't work as expected
akeonly opened this issue · 4 comments
I tried this line without internet access and after approximately 9 seconds later it return error "Error: Couldn't find your IP"
publicIp.v4({timeout:100}).then(value => console.log(value)).catch(err => console.log(err));
I was expecting it to error out within 100 milliseconds, not 9000 milliseconds.
Am I missing something?
Are you using the browser or Node.js version? Can you try the latest version? It has a lot of improvements in the networking code.
The timeout applies to every request, instead of the function as a whole.
Line 160 in 7c155f2
Same problem here, using a timeout of 1000
results in an actual error only after 12 seconds. And looking at the code I understand why: several attempts are made sequentially (with different DNS servers, with different HTTPS servers), and each attempt uses the timeout value. So obviously the overall timeout will be much longer...
So I'd say either use Promise.any
for all the DNS attempts and all the HTTPS attempts, or make it clearer in the documentation that the timeout applies to each individual attempt, and is not a timeout for the publicIp()
request.
I can make a pull request for either of these solutions, if you're OK with one of the two !