Skip to content

Commit 30f2b5a

Browse files
committed
fix: prevent memory leaks and race conditions in poller
1 parent a76a805 commit 30f2b5a

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

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)