Skip to content

Commit dec45b1

Browse files
authored
Merge pull request #852 from snyk/fix/retry-econnreset
fix: retry listing workloads when receiving ECONNRESET
2 parents 88b1eda + e3e74d0 commit dec45b1

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/supervisor/kuberenetes-api-wrappers.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ export const DEFAULT_SLEEP_SEC = 1;
88
export const MAX_SLEEP_SEC = 5;
99
type IKubernetesApiFunction<ResponseType> = () => Promise<ResponseType>;
1010

11+
const RETRYABLE_NETWORK_ERRORS: string[] = [
12+
'ECONNREFUSED',
13+
'ETIMEDOUT',
14+
'ECONNRESET',
15+
];
16+
1117
export async function retryKubernetesApiRequest<ResponseType>(
1218
func: IKubernetesApiFunction<ResponseType>,
1319
): Promise<ResponseType> {
@@ -89,11 +95,7 @@ function shouldRetryRequest(err: IRequestError, attempt: number): boolean {
8995
return false;
9096
}
9197

92-
if (err.code === 'ECONNREFUSED') {
93-
return true;
94-
}
95-
96-
if (err.code === 'ETIMEDOUT') {
98+
if (err.code && RETRYABLE_NETWORK_ERRORS.includes(err.code)) {
9799
return true;
98100
}
99101

test/system/kind.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ test('Kubernetes-Monitor with KinD', async (jestDoneCallback) => {
176176
.get('/apis/apps/v1/namespaces/snyk-monitor/deployments')
177177
.times(1)
178178
.replyWithError({
179-
code: 'ETIMEDOUT',
179+
code: 'ECONNRESET',
180180
});
181181

182182
nock('https://kubernetes-upstream.snyk.io')

0 commit comments

Comments
 (0)