@splitsoftware/splitio-commons 3.1.1-rc.7 → 3.1.1-rc.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -61,9 +61,12 @@ function sdkLifecycleFactory(params, isSharedClient) {
61
61
  }
62
62
  // Stop background jobs
63
63
  syncManager && syncManager.stop();
64
+ // Stop the service API (the auth provider backoff retries specifically) before flushing,
65
+ // so that a pending/never-resolved auth retry (e.g. backend unreachable since startup)
66
+ // doesn't block the flush forever. Any already-cached credential is still usable within
67
+ // the flush, since `stop()` only prevents scheduling further retries.
68
+ serviceApi && serviceApi.stop();
64
69
  return __flush().then(function () {
65
- // Stop the service API (the auth provider backoff retries specifically) after the final flush, so it can still authenticate using the still-valid cached credential
66
- serviceApi && serviceApi.stop();
67
70
  // Cleanup storage
68
71
  return storage.destroy();
69
72
  });
@@ -45,7 +45,7 @@ function authProviderFactory(settings, splitHttpClient, telemetryTracker) {
45
45
  }
46
46
  return {
47
47
  credential: function () {
48
- if (cachedCredential && !isExpired(cachedCredential)) {
48
+ if (stopped || (cachedCredential && !isExpired(cachedCredential))) {
49
49
  return Promise.resolve(cachedCredential);
50
50
  }
51
51
  if (cachedCredential)
@@ -57,7 +57,8 @@ function authProviderFactory(settings, splitHttpClient, telemetryTracker) {
57
57
  },
58
58
  stop: function () {
59
59
  stopped = true;
60
- cachedCredential = undefined;
60
+ // Keep any already-cached credential usable (e.g. by a final flush on destroy);
61
+ // just stop scheduling further retries for an in-flight/failed fetch.
61
62
  inFlightPromise = undefined;
62
63
  backoff.reset();
63
64
  }
@@ -58,9 +58,12 @@ export function sdkLifecycleFactory(params, isSharedClient) {
58
58
  }
59
59
  // Stop background jobs
60
60
  syncManager && syncManager.stop();
61
+ // Stop the service API (the auth provider backoff retries specifically) before flushing,
62
+ // so that a pending/never-resolved auth retry (e.g. backend unreachable since startup)
63
+ // doesn't block the flush forever. Any already-cached credential is still usable within
64
+ // the flush, since `stop()` only prevents scheduling further retries.
65
+ serviceApi && serviceApi.stop();
61
66
  return __flush().then(function () {
62
- // Stop the service API (the auth provider backoff retries specifically) after the final flush, so it can still authenticate using the still-valid cached credential
63
- serviceApi && serviceApi.stop();
64
67
  // Cleanup storage
65
68
  return storage.destroy();
66
69
  });
@@ -42,7 +42,7 @@ export function authProviderFactory(settings, splitHttpClient, telemetryTracker)
42
42
  }
43
43
  return {
44
44
  credential: function () {
45
- if (cachedCredential && !isExpired(cachedCredential)) {
45
+ if (stopped || (cachedCredential && !isExpired(cachedCredential))) {
46
46
  return Promise.resolve(cachedCredential);
47
47
  }
48
48
  if (cachedCredential)
@@ -54,7 +54,8 @@ export function authProviderFactory(settings, splitHttpClient, telemetryTracker)
54
54
  },
55
55
  stop: function () {
56
56
  stopped = true;
57
- cachedCredential = undefined;
57
+ // Keep any already-cached credential usable (e.g. by a final flush on destroy);
58
+ // just stop scheduling further retries for an in-flight/failed fetch.
58
59
  inFlightPromise = undefined;
59
60
  backoff.reset();
60
61
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@splitsoftware/splitio-commons",
3
- "version": "3.1.1-rc.7",
3
+ "version": "3.1.1-rc.8",
4
4
  "description": "Split JavaScript SDK common components",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",
@@ -70,9 +70,11 @@ export function sdkLifecycleFactory(params: ISdkFactoryContext, isSharedClient?:
70
70
  // Stop background jobs
71
71
  syncManager && syncManager.stop();
72
72
 
73
+ // Stop the service API (the auth provider backoff retries specifically) before flushing,
74
+ // so that a pending/never-resolved auth retry doesn't block the flush forever
75
+ serviceApi && serviceApi.stop();
76
+
73
77
  return __flush().then(() => {
74
- // Stop the service API (the auth provider backoff retries specifically) after the final flush, so it can still authenticate using the still-valid cached credential
75
- serviceApi && serviceApi.stop();
76
78
  // Cleanup storage
77
79
  return storage.destroy();
78
80
  });
@@ -69,8 +69,8 @@ export function authProviderFactory(settings: ISettings, splitHttpClient: ISplit
69
69
 
70
70
  return {
71
71
  credential(): Promise<IJwtCredential> {
72
- if (cachedCredential && !isExpired(cachedCredential)) {
73
- return Promise.resolve(cachedCredential);
72
+ if (stopped || (cachedCredential && !isExpired(cachedCredential))) {
73
+ return Promise.resolve(cachedCredential!);
74
74
  }
75
75
 
76
76
  if (cachedCredential) log.debug(LOG_PREFIX_SYNC_AUTH + 'cached credential expired');
@@ -84,7 +84,7 @@ export function authProviderFactory(settings: ISettings, splitHttpClient: ISplit
84
84
 
85
85
  stop() {
86
86
  stopped = true;
87
- cachedCredential = undefined;
87
+ // Keep any already-cached credential usable (e.g. by a final flush on destroy)
88
88
  inFlightPromise = undefined;
89
89
  backoff.reset();
90
90
  }