I am using request-promise
module to check whether site is working with proxy or not. I am trying to find the proxies which is fast enough to answer in 5 seconds. Therefore I only add object if request doesn't timeout in 5 seconds.
For some proxies, even though promise resolves, node script hangs for a while. I can't find the reason of this delay. I see that it prints Done
but it hangs. After 1 minute 10 seconds later, script exits. Is this hang due to my code, or operating system issue for open sockets etc?
const rp = require('request-promise');
const testProxies = [
{
"ipAddress": "80.241.219.83",
"port": 3128,
},
{
"ipAddress": "45.55.27.246",
"port": 80
},
{
"ipAddress": "144.217.197.71",
"port": 8080,
},
{
"ipAddress": "104.131.168.255",
"port": 80,
},
];
function CheckSites(sitesArray,site) {
let ps = [];
for (let i = 0; i < sitesArray.length; i++) {
let proxy = sitesArray[i];
let ops = {
method: 'GET',
resolveWithFullResponse: true,
proxy: 'http://' + proxy.ipAddress + ':' + proxy.port,
uri:site,
};
let resp = rp.get(ops);
ps.push(resp);
}
return Promise.all(ps.map(function (p) {
p.time = Date.now();
return p
.then(function (a) {
return {'header':a.headers,'time':Date.now() - p.time};
})
.timeout(5000)
.catch(function (e) {
return {};
})
}))
}
CheckSites(testProxies,'https://www.example.com').then(function (object) {
console.log('Done!');
console.log(object);
}).catch(function (err) {
console.log('Exception: ' + err);
});