diff --git a/package.json b/package.json index 92f6ea8..75c5eef 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@eppo/js-client-sdk-common", - "version": "4.15.1", + "version": "4.15.2", "description": "Common library for Eppo JavaScript SDKs (web, react native, and node)", "main": "dist/index.js", "files": [ diff --git a/src/poller.ts b/src/poller.ts index 386b0e7..065a84f 100644 --- a/src/poller.ts +++ b/src/poller.ts @@ -97,6 +97,7 @@ export default function initPoller( stopped = true; if (nextTimer) { clearTimeout(nextTimer); + nextTimer = undefined; } logger.info('Eppo SDK polling stopped'); } @@ -104,6 +105,10 @@ export default function initPoller( async function poll() { if (stopped) { + if (nextTimer) { + clearTimeout(nextTimer); + nextTimer = undefined; + } return; } @@ -134,10 +139,14 @@ export default function initPoller( `Eppo SDK reached maximum of ${failedAttempts} failed polling attempts. Stopping polling`, ); stop(); + return; } } - setTimeout(poll, nextPollMs); + // Check stopped state again before setting up next timer to handle race condition + if (!stopped) { + nextTimer = setTimeout(poll, nextPollMs); + } } return {