Skip to content

Commit 08aa26f

Browse files
iamdoronnodkz
authored andcommitted
fix: clearTimeout when waiting for primary
1 parent aaac457 commit 08aa26f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/mongodb-memory-server-core/src/MongoMemoryReplSet.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,9 @@ export default class MongoMemoryReplSet extends EventEmitter {
263263
}
264264

265265
async _waitForPrimary(timeout: number = 30000): Promise<void> {
266+
let timeoutId: NodeJS.Timeout | undefined;
266267
const timeoutPromise = new Promise((resolve, reject) => {
267-
let id = setTimeout(() => {
268-
clearTimeout(id);
268+
timeoutId = setTimeout(() => {
269269
reject('Timed out in ' + timeout + 'ms. When waiting for primary.');
270270
}, timeout);
271271
});
@@ -281,6 +281,10 @@ export default class MongoMemoryReplSet extends EventEmitter {
281281
timeoutPromise,
282282
]);
283283

284+
if (timeoutId != null) {
285+
clearTimeout(timeoutId);
286+
}
287+
284288
this.debug('_waitForPrimary detected one primary instance ');
285289
}
286290
}

0 commit comments

Comments
 (0)