Skip to content

Commit de32f36

Browse files
author
Arthur Granado
committed
fix: retry API requests when receiving error code EAI_AGAIN
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.
1 parent e89c778 commit de32f36

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/transmitter/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,9 @@ function shouldRetryRequest(err: IRequestError, stillHaveRetries: boolean): bool
122122
return true;
123123
}
124124

125+
if (err.code === 'EAI_AGAIN') {
126+
return true;
127+
}
128+
125129
return false;
126130
}

test/system/kind.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ tap.test('Kubernetes-Monitor with KinD', async (t) => {
103103
message: 'socket hang up',
104104
});
105105

106+
nock('https://kubernetes-upstream.snyk.io')
107+
.post('/api/v1/dependency-graph')
108+
.times(1)
109+
.replyWithError({
110+
code: 'EAI_AGAIN',
111+
message: 'getaddrinfo EAI_AGAIN kubernetes-upstream.snyk.io',
112+
});
113+
106114
nock('https://kubernetes-upstream.snyk.io')
107115
.post('/api/v1/dependency-graph')
108116
.times(1)

0 commit comments

Comments
 (0)