-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Implement RN SDK EventSource jitter backoff. #359
fix: Implement RN SDK EventSource jitter backoff. #359
Conversation
… only return well defined auto env objects.
… where single contexts with attributes called ld_application and ld_device are not added with auto env attributes.
… into yus/rn-sdk-auto-env
This pull request has been linked to Shortcut Story #225912: Implement rn eventsource jitter backoff. |
const maxRetryDelay = 30 * 1000; // Maximum retry delay 30 seconds. | ||
const jitterRatio = 0.5; // Delay should be 50%-100% of calculated time. | ||
|
||
export function backoff(base: number, retryCount: number) { | ||
const delay = base * Math.pow(2, retryCount); | ||
return delay > maxRetryDelay ? maxRetryDelay : delay; | ||
} | ||
|
||
export function jitter(computedDelayMillis: number) { | ||
return computedDelayMillis - Math.trunc(Math.random() * jitterRatio * computedDelayMillis); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicated from legacy js-common-sdk.
// GOTCHA: Ignore the server retry recommendation. Use our own custom getNextRetryDelay logic. | ||
// this.pollingInterval = retry; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original source code uses the server recommended retry seconds but we don't need that for our purpose.
@@ -128,16 +143,18 @@ export default class EventSource<E extends string = never> { | |||
|
|||
if (this.xhr.status >= 200 && this.xhr.status < 400) { | |||
if (this.status === this.CONNECTING) { | |||
this.retryCount = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typically we would only reset this after having been active for 1 minute.
🤖 I have created a release *beep* *boop* --- <details><summary>akamai-edgeworker-sdk-common: 1.1.0</summary> ## [1.1.0](akamai-edgeworker-sdk-common-v1.0.6...akamai-edgeworker-sdk-common-v1.1.0) (2024-02-06) ### Features * React-native support for auto-env attributes. Only affects react-native package. ([deea99c](deea99c)) * Update eslint jest configuration and versions. ([deea99c](deea99c)) ### Dependencies * The following workspace dependencies were updated * dependencies * @launchdarkly/js-server-sdk-common bumped from ^2.1.3 to ^2.2.0 </details> <details><summary>akamai-server-base-sdk: 2.1.0</summary> ## [2.1.0](akamai-server-base-sdk-v2.0.6...akamai-server-base-sdk-v2.1.0) (2024-02-06) ### Features * React-native support for auto-env attributes. Only affects react-native package. ([deea99c](deea99c)) * Update eslint jest configuration and versions. ([deea99c](deea99c)) ### Dependencies * The following workspace dependencies were updated * dependencies * @launchdarkly/akamai-edgeworker-sdk-common bumped from ^1.0.6 to ^1.1.0 * @launchdarkly/js-server-sdk-common bumped from ^2.1.3 to ^2.2.0 </details> <details><summary>akamai-server-edgekv-sdk: 1.1.0</summary> ## [1.1.0](akamai-server-edgekv-sdk-v1.0.14...akamai-server-edgekv-sdk-v1.1.0) (2024-02-06) ### Features * React-native support for auto-env attributes. Only affects react-native package. ([deea99c](deea99c)) * Update eslint jest configuration and versions. ([deea99c](deea99c)) ### Dependencies * The following workspace dependencies were updated * dependencies * @launchdarkly/akamai-edgeworker-sdk-common bumped from ^1.0.6 to ^1.1.0 * @launchdarkly/js-server-sdk-common bumped from ^2.1.3 to ^2.2.0 </details> <details><summary>cloudflare-server-sdk: 2.4.0</summary> ## [2.4.0](cloudflare-server-sdk-v2.3.3...cloudflare-server-sdk-v2.4.0) (2024-02-06) ### Features * React-native support for auto-env attributes. Only affects react-native package. ([deea99c](deea99c)) * Update eslint jest configuration and versions. ([deea99c](deea99c)) ### Dependencies * The following workspace dependencies were updated * devDependencies * @launchdarkly/js-server-sdk-common-edge bumped from 2.1.3 to 2.2.0 </details> <details><summary>js-client-sdk-common: 0.2.0</summary> ## [0.2.0](js-client-sdk-common-v0.1.2...js-client-sdk-common-v0.2.0) (2024-02-06) ### Features * Implement common client side support for auto environment attributes. ([#356](#356)) ([8d80259](8d80259)) * React-native support for auto-env attributes. Only affects react-native package. ([deea99c](deea99c)) * Update eslint jest configuration and versions. ([deea99c](deea99c)) ### Bug Fixes * Add LDOptions.application name and versionName. ([#358](#358)) ([cd75210](cd75210)) * Add RN SDK offline support through ConnectionMode. ([#361](#361)) ([d97ce82](d97ce82)) * Implement anonymous context processing ([#350](#350)) ([308100d](308100d)) * Improvements and fixes from docs review. ([#362](#362)) ([ba07fbf](ba07fbf)) ### Dependencies * The following workspace dependencies were updated * dependencies * @launchdarkly/js-sdk-common bumped from 2.1.1 to 2.2.0 </details> <details><summary>js-sdk-common: 2.2.0</summary> ## [2.2.0](js-sdk-common-v2.1.1...js-sdk-common-v2.2.0) (2024-02-06) ### Features * Implement common client side support for auto environment attributes. ([#356](#356)) ([8d80259](8d80259)) * Implement common support for auto environment attributes. ([#355](#355)) ([9f562e5](9f562e5)) * React-native support for auto-env attributes. Only affects react-native package. ([deea99c](deea99c)) * Update eslint jest configuration and versions. ([deea99c](deea99c)) ### Bug Fixes * Add LDOptions.application name and versionName. ([#358](#358)) ([cd75210](cd75210)) * Add RN SDK offline support through ConnectionMode. ([#361](#361)) ([d97ce82](d97ce82)) * Implement anonymous context processing ([#350](#350)) ([308100d](308100d)) * RN streamer connection in background and foreground. ([#360](#360)) ([c69b768](c69b768)) </details> <details><summary>js-server-sdk-common: 2.2.0</summary> ## [2.2.0](js-server-sdk-common-v2.1.3...js-server-sdk-common-v2.2.0) (2024-02-06) ### Features * Implement common client side support for auto environment attributes. ([#356](#356)) ([8d80259](8d80259)) * React-native support for auto-env attributes. Only affects react-native package. ([deea99c](deea99c)) * Update eslint jest configuration and versions. ([deea99c](deea99c)) ### Bug Fixes * Add LDOptions.application name and versionName. ([#358](#358)) ([cd75210](cd75210)) ### Dependencies * The following workspace dependencies were updated * dependencies * @launchdarkly/js-sdk-common bumped from 2.1.1 to 2.2.0 </details> <details><summary>js-server-sdk-common-edge: 2.2.0</summary> ## [2.2.0](js-server-sdk-common-edge-v2.1.3...js-server-sdk-common-edge-v2.2.0) (2024-02-06) ### Features * Implement common client side support for auto environment attributes. ([#356](#356)) ([8d80259](8d80259)) * React-native support for auto-env attributes. Only affects react-native package. ([deea99c](deea99c)) * Update eslint jest configuration and versions. ([deea99c](deea99c)) ### Dependencies * The following workspace dependencies were updated * dependencies * @launchdarkly/js-server-sdk-common bumped from 2.1.3 to 2.2.0 </details> <details><summary>node-server-sdk: 9.1.0</summary> ## [9.1.0](node-server-sdk-v9.0.6...node-server-sdk-v9.1.0) (2024-02-06) ### Features * React-native support for auto-env attributes. Only affects react-native package. ([deea99c](deea99c)) * Update eslint jest configuration and versions. ([deea99c](deea99c)) ### Dependencies * The following workspace dependencies were updated * dependencies * @launchdarkly/js-server-sdk-common bumped from 2.1.3 to 2.2.0 </details> <details><summary>node-server-sdk-dynamodb: 6.1.0</summary> ## [6.1.0](node-server-sdk-dynamodb-v6.0.6...node-server-sdk-dynamodb-v6.1.0) (2024-02-06) ### Features * React-native support for auto-env attributes. Only affects react-native package. ([deea99c](deea99c)) * Update eslint jest configuration and versions. ([deea99c](deea99c)) ### Dependencies * The following workspace dependencies were updated * devDependencies * @launchdarkly/node-server-sdk bumped from 9.0.6 to 9.1.0 </details> <details><summary>node-server-sdk-redis: 4.1.0</summary> ## [4.1.0](node-server-sdk-redis-v4.0.6...node-server-sdk-redis-v4.1.0) (2024-02-06) ### Features * React-native support for auto-env attributes. Only affects react-native package. ([deea99c](deea99c)) * Update eslint jest configuration and versions. ([deea99c](deea99c)) ### Dependencies * The following workspace dependencies were updated * devDependencies * @launchdarkly/node-server-sdk bumped from 9.0.6 to 9.1.0 </details> <details><summary>react-native-client-sdk: 0.2.0</summary> ## [0.2.0](react-native-client-sdk-v0.1.5...react-native-client-sdk-v0.2.0) (2024-02-06) ### Features * React-native support for auto-env attributes. Only affects react-native package. ([deea99c](deea99c)) * Update eslint jest configuration and versions. ([deea99c](deea99c)) ### Bug Fixes * Add RN SDK offline support through ConnectionMode. ([#361](#361)) ([d97ce82](d97ce82)) * Implement RN SDK EventSource jitter backoff. ([#359](#359)) ([95e58bd](95e58bd)) * Improvements and fixes from docs review. ([#362](#362)) ([ba07fbf](ba07fbf)) * RN streamer connection in background and foreground. ([#360](#360)) ([c69b768](c69b768)) ### Dependencies * The following workspace dependencies were updated * dependencies * @launchdarkly/js-client-sdk-common bumped from 0.1.2 to 0.2.0 </details> <details><summary>vercel-server-sdk: 1.3.0</summary> ## [1.3.0](vercel-server-sdk-v1.2.3...vercel-server-sdk-v1.3.0) (2024-02-06) ### Features * React-native support for auto-env attributes. Only affects react-native package. ([deea99c](deea99c)) * Update eslint jest configuration and versions. ([deea99c](deea99c)) ### Dependencies * The following workspace dependencies were updated * dependencies * @launchdarkly/js-server-sdk-common-edge bumped from 2.1.3 to 2.2.0 </details> --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This PR adds jitter and backoff logic to the RNEventSource.