diff --git a/lib/request_urls.js b/lib/request_urls.js index 04383d1..ffd0900 100644 --- a/lib/request_urls.js +++ b/lib/request_urls.js @@ -37,13 +37,22 @@ function request_urls(config, urls, callback) { var delay = test_interval.getBackoff(); var getOneUrl = function (){ - if( urls.length === 0 ){ + // check if all responses have been recieved and call the next step in + // processing via the `callback` function + if( Object.keys(responses).length === total_length ){ clearInterval(intervalId); - return callback([]); + return callback( responses ); } var url = urls.pop(); + // if there are no more URLs to send requests for, we might + // be waiting for some to finish, so just return and the next call to + // this function from the ExponentialBackoff manager will try again + if (!url) { + return; + } + const agent = (url.startsWith('https:')) ? httpsAgent : httpAgent; var requestOpts = {