I use the request-promise module to check if the site is working with a proxy server or not. I am trying to find proxies that are fast enough to respond in 5 seconds. Therefore, I only add an object if the request does not expire after 5 seconds.
For some proxies, although the promise is allowed, the node script freezes for a while. I can not find the reason for this delay. I see that it prints Done , but it freezes. After 1 minute 10 seconds, the script will exit. This freezes 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); });
source share