ddsol / speedtest.net

node.js SpeedTest.net client module
MIT License
607 stars 125 forks source link

http.get hang without timeout #68

Closed fmiceli24 closed 5 years ago

fmiceli24 commented 5 years ago

I know this might be a weird very particular situation but I have encountered that in the following environment (on my electron app) the http.get call never invokes the callback unless I set the timeout option.

It does not even time out, but behaves appropriately. If I do not set that option the http.get function does not invoke the callback nor throws an error.

The fix is to set the option just like below.

options.headers = options.headers || {};
options.headers['user-agent'] = options.headers['user-agent'] || 'Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.' + Math.trunc(Math.random() * 400 + 2704) + '.' + Math.trunc(Math.random() * 400 + 103) + ' Safari/537.36';

options.timeout = 20;

http.get(options, function(res) {
    if (res.statusCode === 302) {

Anyway. Just wanted to leave it somewhere. Any suggestions for the timeout value for the get operations?

fmiceli24 commented 5 years ago

Anyone?

ddsol commented 5 years ago

:+1: A PR could be helpful. I don't have a lot of time for SpeedTest these days. The timeout should be fairly high, maybe 500 or so since they are milliseconds.

fmiceli24 commented 5 years ago

That is great! I would do a pull request as soon as I learn how to.

Thanks.

fmiceli24 commented 5 years ago

Created pull request with the change:

https://github.com/ddsol/speedtest.net/pull/69

Let me know if I have to make any changes (this is my first PR!!)

Best,