diff --git a/src/acme2.js b/src/acme2.js index 4300b9c75..f6d113a4c 100644 --- a/src/acme2.js +++ b/src/acme2.js @@ -204,7 +204,7 @@ Acme2.prototype.waitForOrder = async function (orderUrl) { debug(`waitForOrder: ${orderUrl}`); - return await promiseRetry({ times: 15, interval: 20000 }, async () => { + return await promiseRetry({ times: 15, interval: 20000, debug }, async () => { debug('waitForOrder: getting status'); const result = await this.postAsGet(orderUrl); @@ -257,7 +257,7 @@ Acme2.prototype.waitForChallenge = async function (challenge) { debug('waitingForChallenge: %j', challenge); - await promiseRetry({ times: 15, interval: 20000 }, async () => { + await promiseRetry({ times: 15, interval: 20000, debug }, async () => { debug('waitingForChallenge: getting status'); const result = await this.postAsGet(challenge.url); @@ -509,7 +509,7 @@ Acme2.prototype.acmeFlow = async function (hostname, domain, paths) { }; Acme2.prototype.loadDirectory = async function () { - await promiseRetry({ times: 3, interval: 20000 }, async () => { + await promiseRetry({ times: 3, interval: 20000, debug }, async () => { const response = await superagent.get(this.caDirectory).timeout(30000).ok(() => true); if (response.status !== 200) throw new BoxError(BoxError.ACME_ERROR, `Invalid response code when fetching directory : ${response.status}`); @@ -544,9 +544,8 @@ async function getCertificate(vhost, domain, paths, options) { assert.strictEqual(typeof paths, 'object'); assert.strictEqual(typeof options, 'object'); - let attempt = 1; - await promiseRetry({ times: 3, interval: 0 }, async function () { - debug(`getCertificate: attempt ${attempt++}`); + await promiseRetry({ times: 3, interval: 0, debug }, async function () { + debug(`getCertificate: for vhost ${vhost} and domain ${domain}`); const acme = new Acme2(options || { }); return await acme.getCertificate(vhost, domain, paths); diff --git a/src/apptask.js b/src/apptask.js index f4a7f598f..6395e9f48 100644 --- a/src/apptask.js +++ b/src/apptask.js @@ -71,7 +71,7 @@ async function updateApp(app, values) { async function allocateContainerIp(app) { assert.strictEqual(typeof app, 'object'); - await promiseRetry({ times: 10, interval: 0}, async function () { + await promiseRetry({ times: 10, interval: 0, debug }, async function () { const iprange = iputils.intFromIp('172.18.20.255') - iputils.intFromIp('172.18.16.1'); let rnd = Math.floor(Math.random() * iprange); const containerIp = iputils.ipFromInt(iputils.intFromIp('172.18.16.1') + rnd); @@ -221,7 +221,7 @@ async function downloadIcon(app) { const iconUrl = settings.apiServerOrigin() + '/api/v1/apps/' + app.appStoreId + '/versions/' + app.manifest.version + '/icon'; - await promiseRetry({ times: 10, interval: 5000 }, async function () { + await promiseRetry({ times: 10, interval: 5000, debug }, async function () { const [networkError, response] = await safe(superagent.get(iconUrl) .buffer(true) .timeout(30 * 1000) diff --git a/src/dns.js b/src/dns.js index 65b6d19b9..4753d22c3 100644 --- a/src/dns.js +++ b/src/dns.js @@ -207,7 +207,7 @@ async function registerLocations(locations, options, progressCallback) { const ip = await sysinfo.getServerIp(); for (const location of locations) { - const error = await promiseRetry({ times: 200, interval: 5000 }, async function () { + const error = await promiseRetry({ times: 200, interval: 5000, debug }, async function () { progressCallback({ message: `Registering location: ${location.subdomain ? (location.subdomain + '.') : ''}${location.domain}` }); // get the current record before updating it @@ -243,7 +243,7 @@ async function unregisterLocations(locations, progressCallback) { const ip = await sysinfo.getServerIp(); for (const location of locations) { - const error = await promiseRetry({ times: 30, interval: 5000 }, async function () { + const error = await promiseRetry({ times: 30, interval: 5000, debug }, async function () { progressCallback({ message: `Unregistering location: ${location.subdomain ? (location.subdomain + '.') : ''}${location.domain}` }); const [error] = await safe(removeDnsRecords(location.subdomain, location.domain, 'A', [ ip ])); diff --git a/src/services.js b/src/services.js index a590045ff..61bd0b580 100644 --- a/src/services.js +++ b/src/services.js @@ -589,7 +589,7 @@ async function waitForContainer(containerName, tokenEnvName) { const result = await getContainerDetails(containerName, tokenEnvName); - await promiseRetry({ times: 10, interval: 15000 }, async () => { + await promiseRetry({ times: 10, interval: 15000, debug }, async () => { const [networkError, response] = await safe(superagent.get(`https://${result.ip}:3000/healthcheck?access_token=${result.token}`) .timeout(5000) .disableTLSCerts() diff --git a/src/sysinfo/generic.js b/src/sysinfo/generic.js index d9b84a0be..fca8aa8e4 100644 --- a/src/sysinfo/generic.js +++ b/src/sysinfo/generic.js @@ -17,11 +17,8 @@ async function getServerIp(config) { if (process.env.BOX_ENV === 'test') return '127.0.0.1'; - let attempt = 0; - - return await promiseRetry({ times: 10, interval: 5000 }, async () => { - if (attempt) debug(`getServerIp: getting server IP. attempt ${attempt}`); - ++attempt; + return await promiseRetry({ times: 10, interval: 5000, debug }, async () => { + debug('getServerIp: getting server IP'); const [networkError, response] = await safe(superagent.get('https://api.cloudron.io/api/v1/helper/public_ip') .timeout(30 * 1000) diff --git a/src/updater.js b/src/updater.js index 5a0e07e02..7ddb6e6cc 100644 --- a/src/updater.js +++ b/src/updater.js @@ -38,9 +38,8 @@ async function downloadUrl(url, file) { safe.fs.unlinkSync(file); - let retryCount = 0; - await promiseRetry({ times: 10, interval: 5000 }, async function () { - debug(`Downloading ${url} to ${file}. Try ${++retryCount}`); + await promiseRetry({ times: 10, interval: 5000, debug }, async function () { + debug(`Downloading ${url} to ${file}`); const args = `-s --fail ${url} -o ${file}`;