Skip to content

Commit bb3c950

Browse files
fix: Fix cancelling timeout when waitForInitialization throws an exception (#808)
**Requirements** - [x] I have added test coverage for new or changed functionality - [x] I have followed the repository's [pull request submission guidelines](../blob/main/CONTRIBUTING.md#submitting-pull-requests) - [x] I have validated my changes against all supported platform versions **Related issues** https://launchdarkly.atlassian.net/browse/SDK-1132 **Describe the solution you've provided** Previously the timeout was cancelled in a `then()` and would be skipped if the base promise threw an exception. The cancelation was moved to `finally()` where it will always be called regardless of an exception. **Describe alternatives you've considered** N/A **Additional context** N/A
1 parent 85555c7 commit bb3c950

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

packages/shared/sdk-server/src/LDClientImpl.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -940,14 +940,16 @@ export default class LDClientImpl implements LDClient {
940940
if (timeout) {
941941
const cancelableTimeout = cancelableTimedPromise(timeout, 'waitForInitialization');
942942
return Promise.race([
943-
basePromise.then(() => cancelableTimeout.cancel()).then(() => this),
943+
basePromise.then(() => this),
944944
cancelableTimeout.promise.then(() => this),
945-
]).catch((reason) => {
946-
if (reason instanceof LDTimeoutError) {
947-
logger?.error(reason.message);
948-
}
949-
throw reason;
950-
});
945+
])
946+
.catch((reason) => {
947+
if (reason instanceof LDTimeoutError) {
948+
logger?.error(reason.message);
949+
}
950+
throw reason;
951+
})
952+
.finally(() => cancelableTimeout.cancel());
951953
}
952954
return basePromise;
953955
}

0 commit comments

Comments
 (0)