Skip to content

Commit

Permalink
fix: retry API requests when receiving error code EAI_AGAIN
Browse files Browse the repository at this point in the history
 Kubernetes clusters can have timeout because of slow DNS lookup, and it makes some requests return the error code EAI_AGAIN. It should ignore this error and retry transmitting a request if it stills having remaining retries.
  • Loading branch information
Arthur Granado committed Apr 28, 2020
1 parent e89c778 commit de32f36
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/transmitter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,9 @@ function shouldRetryRequest(err: IRequestError, stillHaveRetries: boolean): bool
return true;
}

if (err.code === 'EAI_AGAIN') {
return true;
}

return false;
}
8 changes: 8 additions & 0 deletions test/system/kind.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ tap.test('Kubernetes-Monitor with KinD', async (t) => {
message: 'socket hang up',
});

nock('https://kubernetes-upstream.snyk.io')
.post('/api/v1/dependency-graph')
.times(1)
.replyWithError({
code: 'EAI_AGAIN',
message: 'getaddrinfo EAI_AGAIN kubernetes-upstream.snyk.io',
});

nock('https://kubernetes-upstream.snyk.io')
.post('/api/v1/dependency-graph')
.times(1)
Expand Down

0 comments on commit de32f36

Please sign in to comment.