Skip to content

Commit 470f094

Browse files
committed
fix(ReplSet): add HACK for "Maximum call stack size exceeded" in MongoClient topology
Closes #221
1 parent f9c80d2 commit 470f094

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,17 @@ export default class MongoMemoryReplSet extends EventEmitter {
242242

243243
try {
244244
const db = await conn.db(this.opts.replSet.dbName);
245+
246+
// MongoClient HACK which helps to avoid the following error:
247+
// "RangeError: Maximum call stack size exceeded"
248+
// in ./node_modules/mongodb/lib/core/sdam/topology_description.js:263:51
249+
// Under the hood initiated server topology has type `RSGhost`
250+
// and this server does not support session
251+
// so for skipping the following code
252+
// https://github.com/mongodb/node-mongodb-native/blob/dc70c2de7d3dae2617708c45a1ea695d131e15f3/lib/operations/execute_operation.js#L33-L39
253+
// we just override shouldCheckForSessionSupport() method for current connection instance
254+
(db as any).topology.shouldCheckForSessionSupport = () => false;
255+
245256
this.admin = db.admin();
246257
const members = uris.map((uri, idx) => ({ _id: idx, host: getHost(uri) }));
247258
const rsConfig = {

0 commit comments

Comments
 (0)