Skip to content

Conversation

@yusinto
Copy link
Contributor

@yusinto yusinto commented Apr 8, 2024

This is a bugfix. Previously, any error event from the emitter rejects the identify promise, which is incorrect.

new Promise<void>((_res, reject) => {
setTimeout(() => {
const e = `${taskName} timed out after ${t} seconds.`;
logger?.error(e);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not log here because a Promise once created will always run so this will always run, which is futile.

Comment on lines -31 to -35
const unauthorized: LDStreamingError = {
code: 401,
name: 'LaunchDarklyStreamingError',
message: 'test-error',
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error mock should be an error object and not a plain js object.

variationIndex: null,
});
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variation tests are moved to its own test file to make this file size manageable.

Comment on lines +82 to +87
this.emitter.on('change', (c: LDContext, changedKeys: string[]) => {
this.logger.debug(`change: context: ${JSON.stringify(c)}, flags: ${changedKeys}`);
});
this.emitter.on('error', (c: LDContext, err: any) => {
this.logger.error(`error: ${err}, context: ${JSON.stringify(c)}`);
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was moved from createIdentifyPromise because it's more efficient to run this once on construction rather than on every identify. Another important change to note is now these just log errors. The error listener does not reject.

};
this.identifyErrorListener = (c: LDContext, err: Error) => {
this.logger.debug(`error: ${err}, context: ${JSON.stringify(c)}`);
reject(err);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the bug where any error will reject the identify promise.

});

return { identifyPromise: raced, identifyResolve: res };
return { identifyPromise: raced, identifyResolve: res, identifyReject: rej };
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Include reject so we can manually reject the identify promise if needed.

this.diagnosticsManager,
(e) => {
this.logger.error(e);
identifyReject(e);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If streamer errors, reject the identify promise. This maybe more relevant during the initial connection to streamer and when PUT is being processed. The other PATCH/DELETE commands come afterwards and by that time the identify promise will already be done so any errors that happens then is moot to the identify promise.

`Unknown feature flag "${flagKey}"; returning default value ${defVal}.`,
);
this.logger.error(error);
this.emitter.emit('error', this.context, error);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Emit error now logs the error so there's no need to duplicate here.

* 2. The identify timeout is exceeded. In client SDKs this defaults to 5s.
* You can customize this timeout with {@link LDIdentifyOptions | identifyOptions}.
*
* 3. A streaming error occurs.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added these improved comments to include rejection scenarios. Will close #425 in favor of this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make 3 more abstract to account for polling or other initialization methods.

A network error is encountered during initialization.
or
An error is encountered accessing flag values from LaunchDarkly.

Copy link
Member

@kinyoklion kinyoklion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with comment.

@yusinto yusinto merged commit a019dd6 into main Apr 9, 2024
@yusinto yusinto deleted the yus/sc-239327/emitting-error-can-incorrectly-reject-identify branch April 9, 2024 17:52
@github-actions github-actions bot mentioned this pull request Apr 9, 2024
yusinto added a commit that referenced this pull request Apr 9, 2024
🤖 I have created a release *beep* *boop*
---


<details><summary>akamai-edgeworker-sdk-common: 1.1.3</summary>

##
[1.1.3](akamai-edgeworker-sdk-common-v1.1.2...akamai-edgeworker-sdk-common-v1.1.3)
(2024-04-09)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @launchdarkly/js-server-sdk-common bumped from ^2.2.2 to ^2.2.3
</details>

<details><summary>akamai-server-base-sdk: 2.1.3</summary>

##
[2.1.3](akamai-server-base-sdk-v2.1.2...akamai-server-base-sdk-v2.1.3)
(2024-04-09)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
* @launchdarkly/akamai-edgeworker-sdk-common bumped from ^1.1.2 to
^1.1.3
    * @launchdarkly/js-server-sdk-common bumped from ^2.2.2 to ^2.2.3
</details>

<details><summary>akamai-server-edgekv-sdk: 1.1.3</summary>

##
[1.1.3](akamai-server-edgekv-sdk-v1.1.2...akamai-server-edgekv-sdk-v1.1.3)
(2024-04-09)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
* @launchdarkly/akamai-edgeworker-sdk-common bumped from ^1.1.2 to
^1.1.3
    * @launchdarkly/js-server-sdk-common bumped from ^2.2.2 to ^2.2.3
</details>

<details><summary>cloudflare-server-sdk: 2.5.0</summary>

##
[2.5.0](cloudflare-server-sdk-v2.4.2...cloudflare-server-sdk-v2.5.0)
(2024-04-09)


### Features

* JSR support for Cloudflare SDK.
([#415](#415))
([30866f3](30866f3))


### Dependencies

* The following workspace dependencies were updated
  * devDependencies
    * @launchdarkly/js-server-sdk-common-edge bumped from 2.2.2 to 2.2.3
</details>

<details><summary>js-client-sdk-common: 1.1.0</summary>

##
[1.1.0](js-client-sdk-common-v1.0.3...js-client-sdk-common-v1.1.0)
(2024-04-09)


### Features

* Add identify timeout to client-sdk.
([#420](#420))
([5d73dfe](5d73dfe))


### Bug Fixes

* Identify incorrectly rejected in client-sdk
([#426](#426))
([a019dd6](a019dd6))


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @launchdarkly/js-sdk-common bumped from 2.3.1 to 2.4.0
</details>

<details><summary>js-sdk-common: 2.4.0</summary>

##
[2.4.0](js-sdk-common-v2.3.1...js-sdk-common-v2.4.0)
(2024-04-09)


### Features

* Add identify timeout to client-sdk.
([#420](#420))
([5d73dfe](5d73dfe))


### Bug Fixes

* Identify incorrectly rejected in client-sdk
([#426](#426))
([a019dd6](a019dd6))
</details>

<details><summary>js-server-sdk-common: 2.2.3</summary>

##
[2.2.3](js-server-sdk-common-v2.2.2...js-server-sdk-common-v2.2.3)
(2024-04-09)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @launchdarkly/js-sdk-common bumped from 2.3.1 to 2.4.0
</details>

<details><summary>js-server-sdk-common-edge: 2.2.3</summary>

##
[2.2.3](js-server-sdk-common-edge-v2.2.2...js-server-sdk-common-edge-v2.2.3)
(2024-04-09)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @launchdarkly/js-server-sdk-common bumped from 2.2.2 to 2.2.3
</details>

<details><summary>node-server-sdk: 9.2.3</summary>

##
[9.2.3](node-server-sdk-v9.2.2...node-server-sdk-v9.2.3)
(2024-04-09)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @launchdarkly/js-server-sdk-common bumped from 2.2.2 to 2.2.3
</details>

<details><summary>node-server-sdk-dynamodb: 6.1.6</summary>

##
[6.1.6](node-server-sdk-dynamodb-v6.1.5...node-server-sdk-dynamodb-v6.1.6)
(2024-04-09)


### Dependencies

* The following workspace dependencies were updated
  * devDependencies
    * @launchdarkly/node-server-sdk bumped from 9.2.2 to 9.2.3
  * peerDependencies
    * @launchdarkly/node-server-sdk bumped from 9.2.1 to 9.2.3
</details>

<details><summary>node-server-sdk-redis: 4.1.6</summary>

##
[4.1.6](node-server-sdk-redis-v4.1.5...node-server-sdk-redis-v4.1.6)
(2024-04-09)


### Dependencies

* The following workspace dependencies were updated
  * devDependencies
    * @launchdarkly/node-server-sdk bumped from 9.2.2 to 9.2.3
  * peerDependencies
    * @launchdarkly/node-server-sdk bumped from 9.2.1 to 9.2.3
</details>

<details><summary>react-native-client-sdk: 10.1.0</summary>

##
[10.1.0](react-native-client-sdk-v10.0.5...react-native-client-sdk-v10.1.0)
(2024-04-09)


### Features

* Add identify timeout to client-sdk.
([#420](#420))
([5d73dfe](5d73dfe))


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @launchdarkly/js-client-sdk-common bumped from 1.0.3 to 1.1.0
</details>

<details><summary>vercel-server-sdk: 1.3.4</summary>

##
[1.3.4](vercel-server-sdk-v1.3.3...vercel-server-sdk-v1.3.4)
(2024-04-09)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @launchdarkly/js-server-sdk-common-edge bumped from 2.2.2 to 2.2.3
</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>
Co-authored-by: Yusinto Ngadiman <yusinto@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants