From e71641363a23b943b215a412e9592b928ec53853 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Fri, 24 Apr 2020 16:33:26 +0200
Subject: [PATCH] fix(npm): randomize retry delay

---
 lib/datasource/npm/get.ts | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/lib/datasource/npm/get.ts b/lib/datasource/npm/get.ts
index c7e84efd23..dc670aa132 100644
--- a/lib/datasource/npm/get.ts
+++ b/lib/datasource/npm/get.ts
@@ -256,8 +256,13 @@ export async function getDependency(
           err.code === 'ETIMEDOUT') &&
         retries > 0
       ) {
-        logger.warn({ pkgUrl, errName: err.name }, 'Retrying npm error');
-        await delay(5000);
+        // Delay a random time to avoid contention
+        const delaySeconds = 5 + Math.round(Math.random() * 25);
+        logger.warn(
+          { pkgUrl, errName: err.name, delaySeconds },
+          'Retrying npm error'
+        );
+        await delay(1000 * delaySeconds);
         return getDependency(packageName, retries - 1);
       }
       if (err.name === 'ParseError' && err.body) {
-- 
GitLab