From 3a014f4482258976b438ebedf691aebe4b4f05b0 Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Thu, 17 Oct 2019 23:29:15 +0200 Subject: [PATCH] fix: don't loop if max tunnel size is reached --- packages/metascraper-media-provider/bench/constants.js | 2 +- .../src/get-media/provider/generic.js | 9 ++++----- .../src/get-media/provider/twitter.js | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/metascraper-media-provider/bench/constants.js b/packages/metascraper-media-provider/bench/constants.js index e15eed0f3..81d18d5dd 100644 --- a/packages/metascraper-media-provider/bench/constants.js +++ b/packages/metascraper-media-provider/bench/constants.js @@ -1,6 +1,6 @@ module.exports = { apiKey: process.env.MICROLINK_API_KEY, - proxies: [process.env.PROXY_ONE, process.env.PROXY_TWO], + proxies: process.env.PROXIES.split(','), urls: [ 'https://twitter.com/Tour_du_Rwanda/status/1111166645475700737', 'https://twitter.com/Visit_Murcia/status/1036982439829225472', diff --git a/packages/metascraper-media-provider/src/get-media/provider/generic.js b/packages/metascraper-media-provider/src/get-media/provider/generic.js index 00c5e120c..c484c86ff 100644 --- a/packages/metascraper-media-provider/src/get-media/provider/generic.js +++ b/packages/metascraper-media-provider/src/get-media/provider/generic.js @@ -57,8 +57,7 @@ const makeError = ({ rawError, url, flags }) => { } module.exports = ({ tunnel, onError, userAgent, cacheDir }) => { - const retry = expirableCounter(1) - + const retry = expirableCounter() return async url => { let data = {} do { @@ -71,11 +70,11 @@ module.exports = ({ tunnel, onError, userAgent, cacheDir }) => { } catch (rawError) { const err = makeError({ rawError, url, flags }) debug('getInfo:err', err.message) - retry.incr() onError(err, url) - if (!(tunnel && isTwitterRateLimit(url, err))) return data + if (!tunnel && isTwitterRateLimit(url, err)) return data + retry.incr() } - } while (isEmpty(data)) + } while (isEmpty(data) && retry.val() < tunnel.size()) return data } } diff --git a/packages/metascraper-media-provider/src/get-media/provider/twitter.js b/packages/metascraper-media-provider/src/get-media/provider/twitter.js index 89badf7da..9ab140d2d 100644 --- a/packages/metascraper-media-provider/src/get-media/provider/twitter.js +++ b/packages/metascraper-media-provider/src/get-media/provider/twitter.js @@ -46,7 +46,7 @@ const createGuestToken = ({ userAgent, tunnel }) => { debug('guestToken:err', err.message) retry.incr() } - } while (!token) + } while (!token && retry.val() < tunnel.size()) return token }