Skip to content

Commit d4568ca

Browse files
Merge pull request #130 from EmilianoSanchez/fix-retry-condition
Fix: the SDK doesn't retry on some recoverable network errors
2 parents ac79c64 + bda82ce commit d4568ca

File tree

6 files changed

+68
-38
lines changed

6 files changed

+68
-38
lines changed

package-lock.json

Lines changed: 18 additions & 14 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.8",
3+
"version": "1.8.9",
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: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -320,20 +320,6 @@ export default class Client {
320320
}
321321

322322
private axiosRetryCondition(error) {
323-
if (axiosRetry.isNetworkOrIdempotentRequestError(error)) {
324-
return true;
325-
}
326-
327-
// retry if connection is aborted
328-
if (error.code === 'ECONNABORTED') {
329-
return true;
330-
}
331-
332-
// DNS issues, service down, etc
333-
if (error.code === 'ENOTFOUND' || error.code === 'ECONNREFUSED') {
334-
return true;
335-
}
336-
337323
// Auth is a POST request so not covered by isNetworkOrIdempotentRequestError and it's not an aborted connection
338324
const status = error?.response?.status;
339325
const url = error?.config?.url ?? '';
@@ -343,14 +329,8 @@ export default class Client {
343329
return false;
344330
}
345331

346-
if (
347-
url.includes('client/auth') && ((status >= 500 && status <= 599) || (status >= 400 && status <= 499))
348-
) {
349-
return true;
350-
}
351-
352-
// Otherwise do not retry
353-
return false;
332+
// Otherwise retry: if connection is aborted, DNS issues, service down, network errors, etc
333+
return true;
354334
}
355335

356336
private createAxiosInstanceWithRetries(

src/streaming.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ export class StreamProcessor {
284284
}
285285

286286
clearTimeout(this.retryTimeout);
287+
this.retryTimeout = undefined;
287288

288289
this.readyState = StreamProcessor.CLOSED;
289290
this.log.info('Closing StreamProcessor');

src/types.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,62 @@ import { FeatureConfig, Segment } from './openapi';
33

44
export type Type = boolean | string | number | Record<string, unknown>;
55
export interface Options {
6+
/**
7+
* The URL used to fetch Feature Flag Evaluations. When using the Relay Proxy, change this to: http://localhost:7000
8+
*
9+
* @defaultValue https://config.ff.harness.io/api/1.0
10+
*/
611
baseUrl?: string;
12+
/**
13+
* The URL for posting metrics data to the Feature Flag service. When using the Relay Proxy, change this to: http://localhost:7000
14+
*
15+
* @defaultValue https://events.ff.harness.io/api/1.0
16+
*/
717
eventsUrl?: string;
18+
/**
19+
* The interval in milliseconds that we poll for changes when you are not using streaming mode.
20+
*
21+
* @defaultValue 60000
22+
*/
823
pollInterval?: number;
24+
/**
25+
* The interval in milliseconds to post analytics data to the Feature Flag service.
26+
*
27+
* @defaultValue 60000
28+
*/
929
eventsSyncInterval?: number;
30+
/**
31+
* Set to true to enable streaming mode. Set to false to disable streaming mode.
32+
*
33+
* @defaultValue true
34+
*/
1035
enableStream?: boolean;
36+
/**
37+
* Set to true to enable analytics. Set to false to disable analytics. Note: When enabled, analytics data is posted every `eventsSyncInterval`.
38+
*
39+
* @defaultValue true
40+
*/
1141
enableAnalytics?: boolean;
1242
cache?: KeyValueStore;
1343
store?: AsyncKeyValueStore;
44+
/**
45+
* Set a custom logger to use for logging.
46+
*
47+
* @defaultValue console
48+
*/
1449
logger?: Logger;
1550
tlsTrustedCa?: string;
51+
/**
52+
* Set the timeout for requests to the Feature Flag service.
53+
*
54+
* @defaultValue 30000
55+
*/
1656
axiosTimeout?: number;
57+
/**
58+
* Set the number of retries for requests to the Feature Flag service.
59+
*
60+
* @defaultValue Infinity
61+
*/
1762
axiosRetries?: number;
1863
}
1964

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.8';
1+
export const VERSION = '1.8.9';

0 commit comments

Comments
 (0)