Skip to content

Commit c09e4ab

Browse files
authored
fix: [FFM_12484]: Node SDK doesn't retry after initialisation failure (#125)
* fix: [FFM_12484]: Node SDK doesn't retry after initialisation failure * increase what we check on
1 parent d5a70a3 commit c09e4ab

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@harnessio/ff-nodejs-server-sdk",
3-
"version": "1.8.6",
3+
"version": "1.8.7",
44
"description": "Feature flags SDK for NodeJS environments",
55
"main": "dist/cjs/index.js",
66
"module": "dist/esm/index.mjs",

src/client.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,22 @@ export default class Client {
322322
return true;
323323
}
324324

325+
// DNS issues, service down, etc
326+
if (error.code === 'ENOTFOUND' || error.code === 'ECONNREFUSED') {
327+
return true;
328+
}
329+
325330
// Auth is a POST request so not covered by isNetworkOrIdempotentRequestError and it's not an aborted connection
326331
const status = error?.response?.status;
327332
const url = error?.config?.url ?? '';
328333

334+
if (url.includes('client/auth') && status === 403) {
335+
// No point retrying with wrong SDK key
336+
return false;
337+
}
338+
329339
if (
330-
url.includes('client/auth') &&
331-
status >= 500 &&
332-
status <= 599
340+
url.includes('client/auth') && ((status >= 500 && status <= 599) || (status >= 400 && status <= 499))
333341
) {
334342
return true;
335343
}
@@ -357,7 +365,7 @@ export default class Client {
357365
const instance: AxiosInstance = axios.create(axiosConfig);
358366
axiosRetry(instance, {
359367
retries: options.axiosRetries,
360-
retryDelay: axiosRetry.exponentialDelay,
368+
retryDelay: (retryCount, error) => axiosRetry.exponentialDelay((retryCount > 7 ? 7 : retryCount), error, 500), // cap to 7 to avoid exponential delays getting too long
361369
retryCondition: this.axiosRetryCondition,
362370
shouldResetTimeout: true,
363371
onRetry: (retryCount, error, requestConfig) => {

src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const defaultOptions: Options = {
4545
store: new FileStore(),
4646
logger: new ConsoleLog(),
4747
axiosTimeout: 30000,
48-
axiosRetries: 3,
48+
axiosRetries: Infinity, // Retry forever unless explicitly overridden
4949
};
5050

5151
const TARGET_SEGMENT_RULES_QUERY_PARAMETER = 'v2';

src/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const VERSION = '1.8.6';
1+
export const VERSION = '1.8.7';

0 commit comments

Comments
 (0)