Skip to content

Commit

Permalink
fix(npm): randomize retry delay
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Apr 24, 2020
1 parent 89e2240 commit e716413
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/datasource/npm/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit e716413

Please sign in to comment.