Skip to content

Commit 8824a52

Browse files
authored
[FFL-648] stop polling (#292)
* fix: prevent memory leaks and race conditions in poller * chore: bump patch version
1 parent a76a805 commit 8824a52

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eppo/js-client-sdk-common",
3-
"version": "4.15.1",
3+
"version": "4.15.2",
44
"description": "Common library for Eppo JavaScript SDKs (web, react native, and node)",
55
"main": "dist/index.js",
66
"files": [

src/poller.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,18 @@ export default function initPoller(
9797
stopped = true;
9898
if (nextTimer) {
9999
clearTimeout(nextTimer);
100+
nextTimer = undefined;
100101
}
101102
logger.info('Eppo SDK polling stopped');
102103
}
103104
};
104105

105106
async function poll() {
106107
if (stopped) {
108+
if (nextTimer) {
109+
clearTimeout(nextTimer);
110+
nextTimer = undefined;
111+
}
107112
return;
108113
}
109114

@@ -134,10 +139,14 @@ export default function initPoller(
134139
`Eppo SDK reached maximum of ${failedAttempts} failed polling attempts. Stopping polling`,
135140
);
136141
stop();
142+
return;
137143
}
138144
}
139145

140-
setTimeout(poll, nextPollMs);
146+
// Check stopped state again before setting up next timer to handle race condition
147+
if (!stopped) {
148+
nextTimer = setTimeout(poll, nextPollMs);
149+
}
141150
}
142151

143152
return {

0 commit comments

Comments
 (0)